javascript - Object.assign, values only -
i have 2 objects. 1 source object, , deep copy of source object. same keys exist in each, deep copy may have different values source object. instance:
{ id: 123, people: [{ name: "bob", age: 50 }, { name: "alice", age: 40 }] } , { id: 123, people: [{ name: "bob", age: 51 // bob older }, { name: "alice", age: 40 }] } please note object deeper many more keys/objects/arrays/values.
i want apply values (and values only) updated copy on source object.
the important piece need maintain original reference points of source object. means cannot of following:
sourceobject = updatedcopiedobject; because overwrites source object , breaks references source object
object.assign(sourceobject, updatedcopiedobject); because, docs say:
properties in target object overwritten properties in sources if have same key. later sources' properties overwrite earlier ones.
in other words, overwrites references of source object.
what need object.assign do, not overwrite properties - just change values properties match.
i don't know of built in method in necessary recursive/deep manner. can write method does, wanted see if there solution problem first.
i don't know of built in method in necessary recursive/deep manner. can write method does, wanted see if there solution problem first.
no, there not.
Comments
Post a Comment