con_data = {
"0": {
"Actual1920": 2379403,
"Budget1920": 10121051.161450788,
"CostOwner": "Dr. Ratnavat",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Salary",
"LedgereType": "Salary-Teaching",
"RemainingAmount": 7741648.161450788,
"leadgerLevel": "EBITDA"
},
"1": {
"Actual1920": 0,
"Budget1920": 0,
"CostOwner": "Dr. Ratnavat",
"LedgerBudget": "Salary",
"LedgerType": "Salary-Teaching",
"RemainingAmount": 0
},
"2": {
"Actual1920": 0,
"Budget1920": 0,
"CostOwner": "Dr. Ratnavat",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Salary",
"LedgereType": "Salary-Contract & Professional",
"RemainingAmount": 0,
"leadgerLevel": "EBITDA"
},
"3": {
"Actual1920": 0,
"Budget1920": 540098.7555555556,
"CostOwner": "Vineeta S",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Admission",
"LedgereType": "Admission-Referral",
"RemainingAmount": 540098.7555555556,
"leadgerLevel": "EBITDA"
},
"4": {
"Actual1920": 0,
"Budget1920": 40835.600000000006,
"CostOwner": "Vineeta S",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Admission",
"LedgereType": "Admission-Others",
"RemainingAmount": 40835.600000000006,
"leadgerLevel": "EBITDA"
},
"5": {
"Actual1920": 0,
"Budget1920": 1690058.304,
"CostOwner": "Nitin P",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Advertisement",
"LedgereType": "Advertisement- Print & Others",
"RemainingAmount": 1690058.304,
"leadgerLevel": "EBITDA"
},
// Other objects excluded for brevity
this.new_data = Object.keys(this.con_data).reduce( (acc,currentKey)=>{
const item = this.con_data[currentKey]
const ledgetBudgetType = item.LedgerBudget
if( !acc[ledgetBudgetType] ){
acc[ledgetBudgetType] = {}
}
const size = Object.keys(acc[ledgetBudgetType]).length
acc[size] = item
return acc
}, {})
console.log("New Data :",this.new_data);
The parent key will be the LedgerBudget key, and I want the data formatted as shown below:
new_data = {
'Salary' : {
"0" : {
"Actual1920": 2379403,
"Budget1920": 10121051.161450788,
"CostOwner": "Dr. Ratnavat",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Salary",
"LedgereType": "Salary-Teaching",
"RemainingAmount": 7741648.161450788,
"leadgerLevel": "EBITDA"
},
"1": {
"Actual1920": 0,
"Budget1920": 0,
"CostOwner": "Dr. Ratnavat",
"LedgerBudget": "Salary",
"LedgerType": "Salary-Teaching",
"RemainingAmount": 0
},
"2": {
"Actual1920": 0,
"Budget1920": 0,
"CostOwner": "Dr. Ratnavat",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Salary",
"LedgereType": "Salary-Contract & Professional",
"RemainingAmount": 0,
"leadgerLevel": "EBITDA"
},
},
"Admission" : {
"0": {
"Actual1920": 0,
"Budget1920": 540098.7555555556,
"CostOwner": "Vineeta S",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Admission",
"LedgereType": "Admission-Referral",
"RemainingAmount": 540098.7555555556,
"leadgerLevel": "EBITDA"
},
"1": {
"Actual1920": 0,
"Budget1920": 40835.600000000006,
"CostOwner": "Vineeta S",
"LTRevExp": "Expense-EB",
"LedgerBudget": "Admission",
"LedgereType": "Admission-Others",
"RemainingAmount": 40835.600000000006,
"leadgerLevel": "EBITDA"
},
}
}