This is an example of what I need to do:
var myarray = [5, 10, 3, 2];
var result1 = myarray[0];
var result2 = myarray[1] + myarray[0];
var result3 = myarray
This question has been answered well by others but I'll leave my solution here too. I tried to be concise without sacrificing clarity.
myarray.reduce((a, e, i) => {
// a: Accumulator; e: current Element; i: current Index
return a.length > 0 ? [...a, e + a[i - 1]] : [e];
}, []);
Map, Filter, Reduce, Find, Some, etc. are highly underrated.