I have an object array that looks like this:
rawData:
0: {name: "cat", count: 2}
1: {name: "dog", count: 5}
2: {name: "fish", count: 3}
and I have a translatedData that multiplies the count field by 2.
newData:
0: {name: "cat", count: 4}
1: {name: "dog", count: 10}
2: {name: "fish", count: 6}
I use the following calculation:
let newData = Object.assign({}, rawData);
newData = Object.keys(newData).map(key => {
let newValue = Math.round(newData[key].all*2);
newData[key].all = newValue;
return newData[key];
});
I use a map to perform this calculation. My issue is when when I console.log both these arrays they both have the calculation. I want the rawData to have its previous state and not be affected by the calculation.I thought object.assign would fix this. What am i doing wrong?