I have two objects. One serves as the original source object, while the other is a deep copy of the source object with potentially different values. For example:
{
id: 123,
people: [{
name: "Bob",
age: 50
}, {
name: "Alice",
age: 40
}]
}
and
{
id: 123,
people: [{
name: "Bob",
age: 51 // Bob is now older
}, {
name: "Alice",
age: 40
}]
}
Keep in mind that the object has multiple nested keys, objects and arrays.
My goal is to update the values (and only the values) from the modified copy back onto the original source object.
The key aspect here is to retain the original reference points of the source object. This means I cannot use either of the following methods:
sourceObject = updatedCopiedObject;
as it would completely replace the source object and disrupt its references
Object.assign(sourceObject, updatedCopiedObject);
since this would lead to property overwriting, violating the need to maintain original references.
What I require is the functionality of Object.assign without property overwriting - simply updating matching properties with new values.
Currently, I am unaware of any built-in method capable of achieving this recursive/deep value-changing process. While I can create a custom method to address this, I am curious if there exists a pre-existing solution to this problem.