I'm trying to add a common array of objects, should be similar fund_asset_class_focus and year, and have to format into an array of arrays as below(["fund_asset..","2017-total allocation",2018,2019]
).
data = [
{
"allocation": 60.30,
"dt": "2017",
"fund_asset_class_focus": "U.S. Fixed Income"
},
{
"allocation": 50,
"dt": "2017",
"fund_asset_class_focus": "U.S. Fixed Income"
}
{
"allocation": 39.80,
"dt": "2018",
"fund_asset_class_focus": "U.S. Fixed Income"
},
{
"allocation": 40.7,
"dt": "2019",
"fund_asset_class_focus": "U.S. Fixed Income"
},
{
"allocation": 20,
"dt": "2018",
"fund_asset_class_focus": "Cash"
},
{
"allocation": 9.7,
"dt": "2018",
"fund_asset_class_focus": "Cash"
}
{
"allocation": 16,
"dt": "2018",
"fund_asset_class_focus": "Credit"
},
{
"allocation": 16,
"dt": "2019",
"fund_asset_class_focus": "Credit"
},
{
"allocation": 16,
"dt": "2019",
"fund_asset_class_focus": "Credit"
}
]
data = [["U.S. Fixed Income",110.30,39.80, 40.7],["Cash",0,29.7,0],["Credit",0,16,32]]
I tried to solve this by using the following code, however, it was unsuccessful in meeting my requirements:
for (let i in data) {
var tempObj = {};
if (obj[years[0]])
tempObj[years[0]] = obj[years[0]];
else
tempObj[years[0]] = {};
if (obj[data[i]["fund_asset_class_focus"]]) {
}
}