I have a JSON with an array of numbers associated with months.
// Example:
let data = {
"12": [110.0, 120.0],
"11": [100.0],
"10": [90.0],
"9": [80.0],
"8": [70.0, 40.0],
"7": [60.0, 50.0],
"6": [50.0, 30.0],
"5": [40.0],
"4": [30.0, 0.0],
"3": [20.0],
"2": [10.0],
"1": [0.0, 10.0, 50.0]
}
I also have 12 variables where I need to save the sum of the values of each array.
// Example:
let value1;
let value2;
[...]
let value11;
let value12;
I'd like to save the values in a single loop but how can I select a different variable in each loop?
let myObj= JSON.parse(data);
for (let i = 1; i <= 12; i++) {
month = i.toString();
value1 = myObj.month.reduce((a, b) => a + b, 0); // How do I select a different variable every loop?
}