this.Num.forEach(item=>{ if (this.Group.length>0) { this.Group.find(key=>key.id===item.id? '':item) this.Group.push(item) }else { this.Group.push(item) } })
Num要遍历,然后匹配Group中找到不一样的key,在push到group里形成一个新数组。
搞那么复杂干嘛,换成这样写不好吗
this.Num.forEach(item=>{ if (!this.Group.some(key => key.id === item.id)) { this.Group.push(item) } })
1.4m articles
1.4m replys
5 comments
56.7k users