In a simple array loop of Javacript as
for (var i=0; i
you need reduce; a built sweet function to get previous and next values of array
[0, 1, 2, 3, 4].reduce(function(previousValue, currentValue, currentIndex, array) { return previousValue + currentValue; });