I have an array as the following:
const data = [
{ Date: "2012", A: 2, B: 3, C: 4 },
{ Date: "2013", A: 4, B: 7, C: 8 },
{ Date: "2014", A: 0.1, B: 0.3, C: 0.4 },
];
I want to multiply specific columns/fields by 100, so I created a new array that holds their keys:
const arr = ["A", "B", "C"];
And then I use .map to multiple those columns:
arr.forEach((element, i) => data.map(a => a[element] * 100));
However, when I check the data array of objects it seems to be unchanged:
const data = [
{ Date: "2012", A: 2, B: 3, C: 4 },
{ Date: "2013", A: 4, B: 7, C: 8 },
{ Date: "2014", A: 0.1, B: 0.3, C: 0.4 },
];
const arr = ["A", "B", "C"];
arr.forEach((element, i) => data.map(a => a[element] * 100));
console.log(data);