数值结构:
有数组 houseList ,projectOptions ,我想对比数组,去除重复部分。最后只想得到 projectOptions 中不重复的部分。
this.houseList = [
{
houseId: "1"
},
{
houseId: "2"
}
];
this.projectOptions = [
{
id: "1"
},
{
id: "2"
},
{
id: "3"
},
{
id: "4"
}
];
采用 .map 和 .includes 进行实现
let Ids = this.houseList.map(item => item.houseId);
let arr = new Array();
this.projectOptions.forEach((item, index) => {
if (!Ids.includes(item.id)) {
arr.push(item);
}
});
this.projectOptions = arr;
网友评论