let array = [
{ id: 1, name: '123' },
{ id: 2, name: '456' },
{ id: 3, name: '678' },
{ id: 4, name: '789' },
{ id: 5, name: '234' }
]
let tempArray= [3, 4]
let date = array.filter(item => tempArray.indexOf(item.id) > -1)
console.log('date', date)
// { id: 3, name: '678' }
// { id: 4, name: '789' }
ES6 比较两个数组 是否含有相同项
最新推荐文章于 2024-03-08 14:04:50 发布