I have two objects as below :
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
}
]
}
Now i need to insert obj2 in a way that the result should be
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 am trying to work on it using push method like:
let onlyCLs = obj2;
metric_clg_json.careerLevelGroups[0].careerLevel.push(onlyCLs);
but this is not working for me. may be i need some loop logic to get to the "careerLevels" node and then insert obj2 just below it.