Object.assign() static method copies all enumerable own properties from one or more source objects to a target object.
syntax ↴
Object.assign(target, source1, source2, /* …, */ sourceN) ↴
target The target object to which we will copy all the properties of the sources and return after it is modified.
source1, …, sourceN The source object(s) whose properties we want to copy.
Properties in the target object are overwritten by properties in the sources if they have the same key.
Later sources' properties overwrite earlier ones.
For copying property definitions (including their enumerability) into prototypes, use Object.getOwnPropertyDescriptor() and Object.defineProperty() instead.
Using the empty object {} as a target object ensures that the properties of the other objects are copied to a new object without modifying the first source object. Otherwise ↴
const myObject1 = {'a': 1, 'b': 1, 'c': 1}; // target object
const myObject2 = {'a': 22, 'b': 22};
const myObject3 = {'b': 333, 'd': 444};
Object.assign(myObject1, myObject2, myObject3);
myObject1 returns ↴
{'a': 22, 'b': 333, 'c:' 1, 'd': 444}
myObject1 is the target object and has been modified.
TypeError is thrown if the property is non-writable.
Object.assign(target, source1, source2, ..., sourceN)