Below is the structure of my data;
{
"questions": ["Large choice of food", "Food quality", "Food freshness"],
"countries": ["Netherlands", "Belgium", "France"],
"values": [
[
[5, 88, 18],
[50, 83, 10],
[29, 78, 80]
],
[
[46, 51, 61],
[95, 21, 15],
[49, 86, 43]
],
[
[7, 46, 92],
[54, 94, 31],
[89, 96, 11]
]
]
}
Here is my script for sorting it;
function calculateTotals() {
var countryS = "France"
var country = data.countries.indexOf(countryS);
var values
for (var question= 0; question < data.questions.length; question++) {
// get the values for the question/country
values = data.values[question][country];
console.log(values)
Currently, this outputs this to the console;
So, currently this script is logging the values for each question indexed by country.
I would like to add together each item in this array. So, from this output I would like to do the following additions;
29 + 49 + 89,
78 + 86 + 96,
80 + 43 + 11
I'm not sure how I can do this?
I thought that perhaps using .pop()/.shift() 3 times might work, or just using [0],[1],[2]. However, after returning a single item in the array, I'm not sure how to add the 3 arrays numbers together?
Hope everything is clear, any help/advice is much appreciate!