JSFiddle - React, Tailwind, and code Playground
JavaScript
var aSelectedDataSet = [
{
__metadata:{},
to_ListTypeGroupAssignment:{
ListTypeGroup:undefined,
ListTypeGroupDescription:undefined
}
},
{
__metadata:{},
to_ListTypeGroupAssignment:{
ListTypeGroup:undefined,
ListTypeGroupDescription:undefined
}
}
];
var oData = {
__metadata:{results:[]},
to_ExcludedTerms:{results:[]},
to_ListTypeGroupAssignment:{
results:[
{
AuthorisationGroup:'AuthorisationGroup 1',
DbKey:'839a45f6-de2b-4bab-90dd-311695868c55',
ListTypeGroup:'ListTypeGroup1',
ListTypeGroupDescription:'ListTypeGroupDescription 1',
ParentKey:'8ae25d47-c3cc-4ee3-a040-ea00505692111',
__metadata:{}
},
{
AuthorisationGroup:'AuthorisationGroup 2',
DbKey:'786a50a2-91e0-4dfd-b1e7-5320c0c16f2c',
ListTypeGroup:'ListTypeGroup2',
ListTypeGroupDescription:'ListTypeGroupDescription 2',
ParentKey:'34bcdc74-ab42-4538-8657-0a2b0473fcb7',
__metadata:{}
}
]
}
};
$(function(){
aSelectedDataSet.forEach(function(currentObject,index){
for (var childObject in currentObject) {
if (! currentObject.hasOwnProperty(childObject))
continue;
if(typeof currentObject[childObject] !== 'object')
continue;
for(var grandChildObject in currentObject[childObject]) {
var objectToClone = oData[childObject]['results'][index][grandChildObject];
if(typeof objectToClone === 'object') {
$.extend(true,currentObject[childObject][grandChildObject],objectToClone);
} else {
currentObject[childObject][grandChildObject] = objectToClone;
}
}
}
});
});
console.log(aSelectedDataSet);