Check out my code snippet:
var data = [[40, 20, 60], [20, 30, 10], [50, 75, 40]];
var averageData = [];
data.forEach(function(entries) {
entries.reduce(function(a, b) {
return a + b[1];
}, 0);
console.log(entries);
});
I want to sum the numbers in each array together.
I'm not sure how to achieve this within the forEach
loop?
Instead of individual arrays, I'm aiming for the output: [120, 60, 165]
.
The goal is to extract the combined totals from nested arrays into a single line.
Looking forward to any advice or suggestions!
Thank you!