场景:this.userMenus = [{id:1},{id:2},{id:3}];row.id = 2 要求:在this.userMenus数组中找row.id,没有添加,有则删除符合条件这一项
const result
= this.userMenus
.some(item
=> {
if (item
.id
=== row
.id
) {
return true
}
})
if (result
) {
for (const item
in this.userMenus
) {
if (this.userMenus
[item
].id
=== row
.id
) {
this.userMenus
.splice(item
, 1)
}
}
} else {
this.userMenus
.push({ id
: row
.id
})
}