I have two objects. One is a source object, and another is a deep copy of the source object. The same keys exist in each, but the deep copy may have different values than the source object. For instance:
{
id: 123,
people: [{
name: "Bob",
age: 50
}, {
name: "Alice",
age: 40
}]
}
and
{
id: 123,
people: [{
name: "Bob",
age: 51 // bob is older now
}, {
name: "Alice",
age: 40
}]
}
sourceObject = updatedCopiedObject;
Object.assign(sourceObject, updatedCopiedObject);
Properties in the target object will be overwritten by properties in
the sources if they have the same key. Later sources' properties will
similarly overwrite earlier ones.
I don't know of any built in method which will do this in the necessary recursive/deep manner. I can write a method which does, but I wanted to see if there was already a solution to this problem first.
No, there is not.