There are two objects that I have:
obj1=
{
'201609': 52,
'201610': 54,
'201611': 56,
metric: 'promotionsOut',
careerLevelGroups:
[ { '201609': 52,
'201610': 54,
'201611': 56,
careerLevelGroup: 'Associate'
}
]
}
obj2=
{'careerLevels': [{
'201609': 21,
'201610': 22,
'201611': 23,
'careerID': 10000120
},
{
'201609': 31,
'201610': 32,
'201611': 33,
'careerID': 10000130
}
]
}
I now want to merge obj2 in a way that the resulting object is as follows:
result =
{
"201609": 52,
"201610": 54,
"201611": 56,
"metric": "PromotionsOut",
"careerLevelGroups": [{
"201609": 52,
"201610": 52,
"201611": 56,
"careerLevelGroup": "Associate",
"careerLevels": [{
"201609": 21,
"201610": 22,
"201611": 23,
"careerID": 10000120
},
{
"201609": 31,
"201610": 32,
"201611": 33,
"careerID": 10000130
}
]
}]
}
I've been attempting to achieve this by using the push method, like so:
let onlyCLs = obj2;
metric_clg_json.careerLevelGroups[0].careerLevel.push(onlyCLs);
However, I'm facing issues with this approach. It seems like I might require a loop logic to access the "careerLevels" node before inserting obj2 right below it.