I have a collection of objects, illustrated here:
var obj = {
"ABC" : {
"name" : "ABC",
"budget" : 0,
"expense" : 0,
"ledgers" : [{
"Actual1920": 10,
"Budget1920": 20,
},
{
"Actual1920": 10,
"Budget1920": 10,
}]
},
"PQR" : {
"name" : "PQR",
"budget" : 0,
"expense" : 0,
"ledgers" : [{
"Actual1920": 10,
"Budget1920": 20,
}]
}
}
The task is to sum up the values under Actual1920 within the ABC object and its Ledgers array, then assign it to ABC's budget. The same process should be applied to compute the total for expense.
Desired Outcome
var obj = {
"ABC" : {
"name" : "ABC",
"budget" : 30,
"expense" : 20,
"ledgers" : [{
"Actual1920": 10,
"Budget1920": 20,
},
{
"Actual1920": 10,
"Budget1920": 10,
}]
},
"PQR" : {
"name" : "PQR",
"budget" : 20,
"expense" : 10,
"ledgers" : [{
"Actual1920": 10,
"Budget1920": 20,
}]
}
}
Add the totals from Actual1920 to expense and Budget1920 to budget accordingly.