es6 两个数组取相同项
2021-01-24 19:15
标签:span OLE indexof lte class sum let log ons es6 两个数组取相同项 标签:span OLE indexof lte class sum let log ons 原文地址:https://www.cnblogs.com/duhui/p/12864488.htmllet arr = [{ id: 1, name: ‘zs‘ }, { id: 2, name: ‘ls‘ }, { id: 3, name: ‘ww‘ }, { id: 4, name: ‘xm‘ }, { id: 5, name: ‘xh‘ },]
let sum = [3, 4, 5]
let date = arr.filter(item => sum.indexOf(item.id) > -1)
console.log(‘date‘, date)
// 0: {id: 3, name: "ww"}
// 1: {id: 4, name: "xm"}
// 2: {id: 5, name: "xh"}