The app I'm working with is outputting an array in javascript like this:
let realData = [];
realData.push({"2021-01-01":"5,000","2021-02-01":"5,000",
"2021-03-01":"5,000","2021-04-01":"5,000",
"2021-05-01":"5,000","2021-06-01":"5,000",
"2021-07-01":"5,000","2021-08-01":"5,000",
"2021-09-01":"5,000","2021-10-01":"5,000",
"2021-11-01":"5,000","2021-12-01":"5,000"});
realData.push({"2021-01-01":"5,000","2021-02-01":"5,000",
"2021-03-01":"5,000","2021-04-01":"5,000",
"2021-05-01":"5,000","2021-06-01":"5,000",
"2021-07-01":"5,000","2021-08-01":"5,000",
"2021-09-01":"5,000","2021-10-01":"5,000",
"2021-11-01":"5,000","2021-12-01":"5,000"});
realData.push({"2021-01-01":"5,000","2021-02-01":"5,000",
"2021-03-01":"5,000","2021-04-01":"5,000",
"2021-05-01":"5,000","2021-06-01":"5,000",
"2021-07-01":"5,000","2021-08-01":"5,000",
"2021-09-01":"5,000","2021-10-01":"5,000",
"2021-11-01":"5,000","2021-12-01":"5,000"});
console.log(realData);
Each line has 12 entries (for each month).
I'm looking at an effective way to cycle through them and sum the same month; combining each object so Jan 2021 would show 20,000 from the above.
I've previously used this code:
var foo = _.chain(data)
.groupBy('month')
.map(function (objects, period) {
return {
month: period,
value: _.sumBy(objects, item => Number(item.value)),
};
})
.value();
which worked really well; but the data I'm using doesn't have named keys (i.e. before I had a JSON file that looked like this:
[
{
"month": "2020-06-01",
"value": "2500.00",
}, ..
Is what I'm trying to achieve possible or do I need to revisit how the data is being stored?