Having two JSON formatted js-objects:
obj1 = { prop1: 1,
prop2: 2,
prop3: 3 }
obj2 = { prop1: 1,
prop2: 3 }
What is the best js-practise to update obj2 into obj1, that also removes properties? Typically in a jQuery/angular context. Resulting in:
obj1 = { prop1: 1, // not updated, nor overwritten
prop2: 3 // updated
} // prop3 removed
Must also deal with nested objects and arrays.
obj1 = obj2;and will do what you asked.