let list = [
{name: 'tom', age: 10},
{name: 'lee', age: 11},
{name: 'rose', age: 12},
{name: 'jane', age: 13}
]
let info = [
{name: 'lee'},
{name: 'rose'}
]
从list里过滤掉info里没有的,
除了用组成新数组的,有没有直接过滤不符合条件,改变原数组的办法或者其他,求集思广益,大神们
除了这种办法
let newList=[]
for(let i=0;i<list.length;i++){
for(let j=0;j<info.length;j++){
if (list[i].name===info[j].name){
newList.push(list[i])
}
}
}
将
let new_info = JSON.stringify(info);
修改为:JSON.stringify(info).split('name').join();
更健壮一些 ;