js merge objects common methods

const person = { name: 'David Walsh', gender: 'Male' };
const tools = { computer: 'Mac', editor: 'Atom' };
const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' };

method

A, ES6 extended operator

const summary = {...person, ...tools, ...attributes};
console.log(summary); 

Output:

Two, 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.

var newObj  = Object.assign(person, tools, attributes);
console.log(newObj);

Output:

 

 

Guess you like

Origin www.cnblogs.com/liushihong21/p/11275719.html