a = [
{ attr: 1, value: 1},
{ attr: 2, value: 2}
]
b= [
{ attr: 1, value: 1}
]
c= [
{ attr: 1: value: 1}
]
需求,找到多个数组中相同的项,组成一个新数组
getCommonList(list, filterStr) {
let commonList = []
list.map((el) => {
if (commonList.length == 0) {
commonList = el
} else {
commonList = commonList.filter((i) => {
const attrs = el.map(item => item[filterStr])
return attrs.includes(i[filterStr]);
})
}
})
return commonList
},
使用
getCommonList([a,b,c], 'attr')