一、案例
let allSaleAttr = [
{
id: 1,
name: "颜色",
},
{
id: 2,
name: "版本",
},
{
id: 3,
name: "尺码",
},
];
let saleAttr = [
{
id: 9,
s_Id: 5,
saleName: "颜色",
ValueList: [],
},
{
id: 10,
s_Id: 5,
saleName: "版本",
ValueList: [],
},
];
//map和filter
let saleAttrIdx = saleAttr.map(item => item.saleName);
const result = allSaleAttr.filter(item => !saleAttrIdx.includes(item.name));
console.log(result);
//filter和every
function fn(allSaleAttr,saleAttr) {
let res = allSaleAttr.filter((item) => {
return saleAttr.every((item1) => {
return item.name != item1.saleName;
});
});
return res;
}
console.log('fn',fn(allSaleAttr,saleAttr));
![](https://i-blog.csdnimg.cn/blog_migrate/20ab9a3c7e49929104d932afc772702a.png)