I have an array of objects:
var myArray = [ { "date" : "03/01/2017", "value" : 2 }, { "date" : "04/01/2017", "value" : 6 }, { "date" : "05/01/2017", "value" : 4 } ];
I need to copy the value and keep the same array with updated values
The result will look like this:
var myArray = [ { "date" : "03/01/2017", "value" : 2 }, { "date" : "04/01/2017", "value" : 8 //(2+6) }, { "date" : "05/01/2017", "value" : 12 //(2+6+4) } ];
I know it exists
[0, 1, 2, 3, 4].reduce(function(accumulator, currentValue, currentIndex, array) { return accumulator + currentValue; });
But I cannot find an example with an object returning objects as well
source share