I have a javascript array with these values:
fbDivHeightsTest = [280,430,408,430,408]
I need a new array with the sum of elements like this:
newArray = [280, 710, 1118, 1548, 1956].
The fbDivHeightsTest[0] + fbDivHeightsTest[1], fbDivHeightsTest[0] + fbDivHeightsTest[1] + fbDivHeightsTest[2] and so on.
I have tried like this, but the reduce function is not returning the result I expect. It returns: 280, 710, 1398, 2818, 5614
sectionsSeclector.each(function(index, item) {
var sum = fbDivHeights.reduce(function(a, b) { return a + b; }, 0);
fbDivHeights.push( $(item).outerHeight() + sum);
});
Can you please help me with this? thanks!
$(item).outerHeight()should not be part of your function.