判断数组中有没有这个元素中的其中一个值,如果有就删除,如果没有就push
const arr2 = [{id: 1}, {id: 2}]; const value2 = {id: 3}; const index = arr2.findIndex(object => object.id === value2.id); if (index === -1) { arr2.push(value2); }else{
arr.splice(index, 1)
}
const arr2 = [{id: 1}, {id: 2}]; const value2 = {id: 3}; const index = arr2.findIndex(object => object.id === value2.id); if (index === -1) { arr2.push(value2); }else{
}