I am trying to loop through an array of arrays with object [[{},{},{}],[{},{},{}]]
, and create a new array that basically "totals" the arrays. I am a bit at a loss on how to achieve this.
My data looks like this:
[ [{ "2017-01-05": 607 }, { "2017-01-06": 430 }, { "2017-01-07": 357 }, { "2017-01-08": 277 }], [{ "2017-01-09": 607 }, { "2017-01-10": 430 }, { "2017-01-11": 357 }, { "2017-01-12": 277 }] ],
I would like to "count" and "label" each week, and total each week. Example:
newArray: [{"Week 1": 1075}, {"Week 2": 1590}]
I know I should probably use a forEach
loop, but then it gets a bit sketchy:
dateArray.forEach( function (arrayWeek) { // push and name etc. functionality });
I would greatly appreciate your assistance and guidance.