- 判斷對(duì)象數(shù)組是否包含某個(gè)屬性
let objArr=[{type:1},{type:2}]
let isExist=objArr.some(item=>item.type==1)
- 判斷對(duì)象數(shù)組是否包含重復(fù)屬性
let objArr=[{type:1},{type:2},{type:3}]
let objArrTypeList = objArr.map((item) => item.type);
for (let index in objArr){
let item=objArr[index]
if (objArrTypeList.indexOf(item.type) !== Number(index)){
console.log(`重復(fù)項(xiàng)索引${Number(index) + 1}`)
}
}
- 數(shù)組交集
arr1.filter((item) => arr2.includes(item))
- 數(shù)組差集
arr1.filter((item) => !arr2.includes(item))
本文摘自 :https://www.cnblogs.com/