I am trying to summarize a nested array with a reduce method . My array of arrays is as follows:
var data = [
[1389740400000, 576],
[1389741300000, 608],
[1389742200000, 624],
[1389743100000, 672],
[1389744000000, 691]
];
I got it:
data.reduce(function(prev, next) { return prev + next[1]; })
data.reduce((prev, next) => prev + next[1])
However, I need only the second value from each (nested) array. Any hints or tips for me? I am trying to sum all the values in an array.
// Edit: Thanks for the answers. The problem was that I missed the entry level at the end.
// es6 solution
data.reduce((prev, next) => prev + next[1], 0)
source
share