I need to create a new array grouping payments by month regardless of the account type given by 3 categories (DEA,ISA,SIPP)
My data is of the form
var arr = [
{ 'DEA','1', 'Jan',1266 },
{ 'ISA','1', 'Jan',621 },
{ 'SIPP','1', 'Jan',552 },
{ 'DEA','2', 'Feb',889 },
{ 'ISA','2', 'Feb',921 },
{ 'SIPP','2', 'Feb',901 },
];
Month No 1 or 2 etc is redundant data, ie. not required in my output
I need to group the payments by month in the following form into a new array:
var newarr =
[
{ 'Jan',2439 },
{ 'Feb',2711 },
];
I have used the following code as my starting point which groups by age category and summates the TOTAL, but I have been unable to apply to my data successfully yet
var arr = [
{ AGENDADOR: 'AGE270', TOTAL : 6},
{ AGENDADOR: 'AGE270', TOTAL : 3},
{ AGENDADOR: 'AGE203', TOTAL : 5},
{ AGENDADOR: 'AGE028', TOTAL : 9},
];
var totals = arr.reduce(function (r, o) {
(r[o.AGENDADOR])? r[o.AGENDADOR] += o.TOTAL : r[o.AGENDADOR] = o.TOTAL;
return r;
}, {});
console.log(totals);
Any help much appreciated to get me started, thanks.
Many Thanks
Colin