What is the best way to sum an object array of varying length that looks like this:
data = [{"category":"category1","months":{"1":34,"2":67,"3":29,...}
{"category":"category2","months":{"1":34,"2":627,"3":292,...}
{"category":"category3","months":{"1":46,"2":665,"3":129,...}
{"category":"category4","months":{"1":624,"2":667,"3":629,...}
{"category":"category5","months":{"1":32,"2":637,"3":299,...}
}]
I want to basically group by month and sum and assign that to a total category. So I would get a new object that looks like the following that I would push to my data object:
{"category":"total","months":{"1":770,"2":2663,"3":1378,...}
I would end up with:
data = [{"category":"category1","months":{"1":34,"2":67,"3":29,...}
{"category":"category2","months":{"1":34,"2":627,"3":292,...}
{"category":"category3","months":{"1":46,"2":665,"3":129,...}
{"category":"category4","months":{"1":624,"2":667,"3":629,...}
{"category":"category5","months":{"1":32,"2":637,"3":299,...}
{"category":"total","months":{"1":770,"2":2663,"3":1378,...}
}]