Let's say I have 2 objects below:
const obj1 = {
propertyA: 'a',
propertyB: 'b',
propertyC: 'c',
}
const obj2 = {
propertyA:'aa',
propertyB:'bb',
.... //so many properties includes all properties in obj1
propertyZ:'zz',
}
I want each property in obj1 has same value of property with the same name in obj2. Right now what I do is assign value of each property in obj1 :
obj1.propertyA = obj2.propertyA;
obj1.propertyB = obj2.propertyB;
obj1.propertyC = obj2.propertyC;
In my actual case obj1 has lots more properties so this is pretty annoying. And so I'm looking for a better way to optimize this, may be a function in Javascript or in some library like Lodash that I don't know. Anyone know how to solve this problem please share with me.
Object.keys(obj1).forEach(k => obj1[k] = obj2[k]);