I have a json object like this.
Each of this json object can have common Product
name, for example orgs[0]
& orgs[3]
have same product name.
"orgs":
[{
"Budget Actual Consumption": "12.00",
"Budget Planned Consumption": "50.00",
"Product": "Loyalty CO-brand"
}, {
"Budget Actual Consumption": "11.00",
"Budget Planned Consumption": "60.00",
"Product": "Loaylty Rebates"
}, {
"Budget Actual Consumption": "10.00",
"Budget Planned Consumption": "7.00",
"Product": "Loaylty Rebates"
}, {
"Budget Actual Consumption": "9.00",
"Budget Planned Consumption": "8.00",
"Product": "Loyalty CO-brand"
}]
Is it possible to create a new array in such a way that it will have unique multiple object each of which have unique product name & other key will be summed up
For example
var someArray = [{
name:"Loyalty CO-brand",
bac:"21" //12+9
pac:"58" //50+8
},{
name:"Loaylty Rebates",
bac:"21" //10+11
pac:"67" //60+7
}]
I tried by first creating an array of unique Product
,then using forEach
twice one inside another. But I could not successfully complete that as I am not sure how will I add up the other keys value when there is a matching Products