Object.assign(source, target) code example
Example 1: object assign
The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the target object.
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
console.log(returnedTarget);
Example 2: copy an object with object.assign
const data = {
user: 'CamperBot',
status: 'offline',
friends: '732,982',
};
const newObject = Object.assign({}, data, {status: 'online'})
console.log(newObject)