不支持

判断数组中有没有这个元素中的其中一个值,如果有就删除,如果没有就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)
}

 

posted @ 2024-02-06 09:15  骑上我的小摩托  阅读(5)  评论(0编辑  收藏  举报