I have an object with the numerical months as the keys for other objects, containing years for keys and Zeros for the initial values.
MonthRow : {
1 : {2017:0,2018:0},
2 : {2017:0,2018:0},
3 : {2017:0,2018:0},
4 : {2017:0,2018:0},
5 : {2017:0,2018:0},
6 : {2017:0,2018:0}
}
After a query I am using the following code to set the values for each of these objects
Object.keys(MainData.MonthRow).forEach(function(key){
MainData.block.forEach(function(element,i,block){
if(key == element.month){
MainData.year.forEach(function(year, j, years){
if(element.year == year && key == element.month){
console.log("This is the Sale: ", element.Sale, "This is the year ", year, key);
console.log(MainData.MonthRow[key], "This is the Month Key");
console.log(MainData.MonthRow[key][year], "This is the year and key");
MainData.MonthRow[key][year]=element.Sale;
console.log(MainData.MonthRow)
}
})
}
});
But after assigning the value using MonthRow[key][year]=element.Sale; it assigns the value to all the months.
My punctual question is how can I assign a value to obj.key.year = value where key and year is a variable?
Recreated the in JSFiddle got the expected result, but on Sails frame work its not working