功能关键字过滤,利用数组A过滤数组B中的值,要求只检测arr中存在的字段,可以用lodash方法
这是我写的
if(!!this.key ) {
let res = [];
this.arr.forEach(i => {
this.arrs.forEach(e => {
if(e[i] === this.keyword) {
res.push(e);
}
})
})
return _.uniqWith(res, _.isEqual)
} else {
return this.arrs;
}
let key = 11;
let arr = ['name', 'age']
let arrs = [{ name: 11, age: 11, sex: '男' }, { name: '11', age: 22, sex: 11 }]
//随便写的,看看就好
if (key) {
var res = arrs.map(i => {
let obj = {};
arr.map(n => {
if (i[n]) obj[n] = i[n];
})
return obj;
})
console.log(res);
}