I want to deeply copy all missing fields into the object shown by the example code below. Is there a quick es6 shortcut for deeply copying the missing properties in the object?
I tried using Object.assign
but the problem is that it replaces someKey
with the second someKey
object, where as I want it to simply copy over all the properties.
Also these objects are just some random demonstrations, let's say the magic code should be property agnostic
const x = {};
const a = { someKey: { first: 1 } };
const b = { someKey: { second: 2 } };
const c = { otherKey: { first: 1 } };
// some magic algorithm to get expected
Object.assign(x, a, b, c); // this doesn't work
const expected = {
someKey: {
first: 1,
second: 2
},
otherKey: {
first: 1
}
};