javascript copy Object.assign () method

Object.assign () method is used to enumerate all the attribute values ​​are copied from one or more source object to the target object. It will return to the target object. Syntax Object.assign (target, ... sources);

parameter:

target: the target object

Sources: Source Object Returns:

*target

Example copies run:

const object1 = {
  a: 1,
  b: 2,
  c: 3
};
const object2 = Object.assign({c: 4, d: 5}, object1);
console.log(object2);
输出:{c: 3, d: 5, a: 1, b: 2}
复制代码

c: 4 = "c: 3 If the target object property with the same key, the attribute will be overwritten source attributes. Later sources attribute will be similarly covered by the earlier property.

Guess you like

Origin blog.csdn.net/weixin_34205076/article/details/91397249