in the following objects:
var prd = {
"id": 1,
"department_id": 42,
"products": [{
"id": 12,
"name": "49da",
"grouped_addons": [{
"addons": [{
"id": "0_0_40",
"name": "rice",
"qty": 0,
"unit_price": "5.00"
},
{
"id": "0_0_41",
"name": "what",
"qty": 1,
"unit_price": "15.00"
}
]
}]
},
{
"id": 12,
"name": "49da",
"grouped_addons": [{
"addons": [{
"id": "0_0_40",
"name": "rice",
"qty": 0,
"unit_price": "5.00"
}, {
"id": "0_0_41",
"name": "what",
"qty": 1,
"unit_price": "15.00"
}]
}]
},
{
"id": 42,
"name": "345dd",
"grouped_addons": [{
"addons": [{
"id": "0_0_42",
"name": "rice",
"qty": 0,
"unit_price": "5.00"
}, {
"id": "0_0_43",
"name": "what",
"qty": 1,
"unit_price": "15.00"
}]
}]
},
{
"id": 48,
"name": "33ffg",
"grouped_addons": [{
"addons": [{
"id": "0_0_44",
"name": "rice",
"qty": 0,
"unit_price": "5.00"
}, {
"id": "0_0_45",
"name": "what",
"qty": 1,
"unit_price": "15.00"
}]
}]
},
{
"id": 48,
"name": "33ffg",
"grouped_addons": [{
"addons": [{
"id": "0_0_44",
"name": "rice",
"qty": 1,
"unit_price": "5.00"
}, {
"id": "0_0_45",
"name": "what",
"qty": 3,
"unit_price": "15.00"
}]
}]
}
]
}
I want to add and merge the qty in the products in prd and the qty in the grouped_addons of the same object in id, and the final result is as follows:
var prd = {
"id": 1,
"department_id": 42,
"products": [{
"id": 12,
"name": "49da",
"grouped_addons": [{
"addons": [{
"id": "0_0_40",
"name": "rice",
"qty": 0,
"unit_price": "5.00"
},
{
"id": "0_0_41",
"name": "what",
"qty": 2,
"unit_price": "15.00"
}
]
}]
},
{
"id": 42,
"name": "345dd",
"grouped_addons": [{
"addons": [{
"id": "0_0_42",
"name": "rice",
"qty": 0,
"unit_price": "5.00"
}, {
"id": "0_0_43",
"name": "what",
"qty": 1,
"unit_price": "15.00"
}]
}]
},
{
"id": 48,
"name": "33ffg",
"grouped_addons": [{
"addons": [{
"id": "0_0_44",
"name": "rice",
"qty": 1,
"unit_price": "5.00"
}, {
"id": "0_0_45",
"name": "what",
"qty": 4,
"unit_price": "15.00"
}]
}]
}
]
}