为数组所有对象添加一个新属性
let addKey = copyList.map(item => {
let obj = {}
obj['key'] = item.id
return { ...item, ...obj }
})
合并两个数组索引所对应的对象
let arr = [
{ youSay: '你说', 'doGO': 'go' },
{ youSay: '你说', 'doGO': 'go' },
{ youSay: '你说', 'doGO': 'go' },
]
let str = [
{ what: '是的呀' },
{ how: '什么呢' },
{ why: '好的呀' },
]
let letMerge = arr.map((item, index) => {
return { ...item, ...str[index] }
})
console.log('letMerge', letMerge);
0: {youSay: '你说', doGO: 'go', what: '是的呀'}
1: {youSay: '你说', doGO: 'go', how: '什么呢'}
2: {youSay: '你说', doGO: 'go', why: '好的呀'}