es6数组相关操作
阅读原文时间:2023年07月16日阅读:1

1. 获取两个数组中某个属性值相等的项

let a=[{name:1},{name:4},{name:3}]
let b=[{name:5},{name:4},{name:2}]
let index = a.findIndex(aItem => b.some(bItem => bItem.name === aItem.name))
console.log(index, a[index]) // 1, {name:4}

2.筛选获取两个数组的共同项

let arr = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]
let brr = [3, 4, 5]
let list = arr.filter(item => brr.indexOf(item.id) > -1)
console.log('list ', list )