Handy JavaScript Utility Methods
31 Dec 2018Update Object state and return a new object by merging the socond onto the first one
const updateObj = (oldObject, newObject) => {
return {
...oldObject,
...newObject
};
};
// usage
let obj = { key1: "value1", key2 : "value2" };
obj = updateObj(obj, { key2 : "value3" });
console.log(obj); // {key1: "value1", key2: "value3"}