I'm trying to add new properties to obj sub in object1. However its getting overwritten
const object1 = {
a: 1,
b: 2,
c: 3,
sub: {
e: 1,
f: 2
}
};
const object2 = Object.assign({
j: 4,
m: 5
}, object1.sub);
console.log(object2);
{ e:1, f:2, j:4, m:5 }? The way you have it written, you are taking object{ j: 4, m: 5 }and adding the properties fromobject1.subto it, then assigning that toobject2.