Since a and b in your case contains a property with same name, when you do something like Object.assign(a,b)the prop property of b overwrites and not merge the prop. Reference
Try the following:
var a = {prop:{a:'1'}}
var b = {prop:{b:'1'}}
var c = {};
c.prop = Object.assign({},a.prop,b.prop);
console.log(c);
Or
You can write your own custom function which can merge the values of the objects with same properties.
Try the following:
function merge(source, target) {
Object.keys(source).forEach((k) => {
if (source[k].constructor.toString().indexOf('Object') > -1) {
&& target[k]) { target[k] = target[k] || {};
merge(source[k], target[k]);
return;
}
target[k] = source[k];
});
return target;
}
var a = {prop:{a: '1'}};
var b = {prop:{ b: '1'}};
var c = {};
[a,b].forEach((e)=>merge(e, c));
console.log(c);