数组,对象常用的删除方法:
1、根据一个数组元素,删除另一个数组中的对象;
var a = [{ id: 15 }, { id: -1 }, { id: 0 }, { id: 3 }, { id: 12.2 }];
var b = [15, 3];
a = a.filter(function (item) {
return b.indexOf(item.id) < 0;
})
console.log(a);
2、一个对象组成的数组中删除另一个数组存在的对象;
//模拟数据:
let arr1 = [
{ code: "123456781",color: "红色"},
{ code: "123456783",color: "黑色"},
{ code: "123456785",color: "白色"}
];
let arr2 = [
{ code: "123456781",color: "红色"},
{ code: "123456782",color: "绿色"},
{ code: "123456783",color: "黑色"},
{ code: "123456784",color: "咖色"},
{ code: "123456785",color: "白色"},
{ code: "12