var obj = [{
name: 'silence',
age: 18
},{
city: 'Nantong',
address: 'XXXX'
},{
like1: 'play',
like2: 'eat'
}];
obj[0] = Object.assign(obj[0], obj[1], obj[2]);
console.log(obj[0]);
第一种方法利用Object.assign();
第二种方法利用es6的...省略号解构;
var obj = [{
name: 'silence',
age: 18
},{
city: 'Nantong',
address: 'XXXX'
},{
like1: 'play',
like2: 'eat'
}];
obj[0] = {...obj[0], ...obj[1], ...obj[2]};
console.log(obj[0]);
网友评论