My data is structured as follows:
{
"questions": ["Variety of food options", "Food quality", "Freshness of food"],
"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]
]
]
}
I have a script for sorting the data like so;
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, the output in the console looks like this;
https://i.sstatic.net/Op0Tr.png
The script currently logs the values for each question indexed by country.
I want to sum up the elements in each array. For example, I would like to add the following numbers from the output;
29 + 49 + 89,
78 + 86 + 96,
80 + 43 + 11
I'm unsure of how to achieve this. I thought about using .pop()/.shift() or [0],[1],[2], but then I am not sure how to sum the numbers within the arrays?
If everything is clear, any guidance or assistance is greatly appreciated!