key()和push()不能连用吗?

                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里形成一个新数组。

阅读 1.8k
1 个回答

搞那么复杂干嘛,换成这样写不好吗

this.Num.forEach(item=>{
    if (!this.Group.some(key => key.id === item.id)) {
        this.Group.push(item)
    }
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题