const person = { name: 'David Walsh', gender: 'Male' }; const tools = { computer: 'Mac', editor: 'Atom' }; const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' };
方法
一、ES6扩展运算符
const summary = {...person, ...tools, ...attributes};
console.log(summary);
输出结果:
二、Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。它将返回目标对象。
var newObj = Object.assign(person, tools, attributes); console.log(newObj);
输出结果: