I have an array with some predefined data
var data = [
{amount:20, speed:100},
{amount:40, speed:50}
];
I am then adding data to the above array
function addMore() {
data = appendObjTo(data, {amount: 1500,speed:100});
}
function appendObjTo(thatArray, newObj) {
const frozenObj = Object.freeze(newObj);
return Object.freeze(thatArray.concat(frozenObj));
}
The data is being added fine, but for some reason, i am unable to change the value of the new data
function runData() {
perSec = 0;
$.each(data, function( key, value ) {
perSecCalc = Math.round(value.speed/60);
perSec += perSecCalc;
// Below line works only for predefined objects, but not objects from "addMore()"
data[key].amount = value.amount-perSec;
});
setTimeout(function() {
runData();
},1000);
}
While the predefined object in "var data" is being changed, the dynamically added data from "addMore" does not change.
How come the new data is not changing ?
Update: See this fiddle