I have a array with 4 element. I want to get a new array which calculates the sum of array elements where number of opereands increases one at a time.
For example I have an array [1000, 2000, 2000, 4000]
.
Result array should be like
[ 1000, 1000 + 2000, 1000 + 2000 + 2000, 1000 + 2000 + 2000 + 4000]
i.e [1000, 3000, 5000, 9000]
var array = [1000, 2000, 2000, 4000];
var newArray = array.map((e,i) => e)
console.log(newArray);
Is there any way to do that using map function ? Or any other way ?