注意下面代码的返回值,为什么?
const target = { type: ''}
const a = ['apple', 'orange', 'balana']
const b = []
a.forEach(type => { b.push(Object.assign(target, {type}))})
console.log(b) //返回 [ { type: 'balana' }, { type: 'balana' }, { type: 'balana' } ]
注意下面代码的返回值,为什么?
const target = { type: ''}
const a = ['apple', 'orange', 'balana']
const b = []
a.forEach(type => { b.push(Object.assign(target, {type}))})
console.log(b) //返回 [ { type: 'balana' }, { type: 'balana' }, { type: 'balana' } ]