score:2

Accepted answer

You can check https://github.com/mbostock/d3/wiki/Arrays for more info but I think you can use the reduce() function here.

i.e:

[0, 2, 4, 2, 2].reduce(function(previousValue, currentValue, currentIndex, array) {
  console.log(previousValue + currentValue);//2,6,8,10
  return previousValue + currentValue;
});

Related Query

More Query from same tag