ES6 比较两个数组 是否含有相同项

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' }

你可能感兴趣的:(vue,jQuery,js,es6)