vararr=[{id:1,name:'1'},{id:2,name:'2'},{id:3,name:'3'},{id:4,name:'4'},{id:5,name:'5'},]lettiaojian=['3','5']//条件数组vartemp=arr.filter(item=>{for(leti=0;iif(tiaojian[i]!==item.name){ returntrue}else{returnfalse}}})console.log(temp)/*[{id:1,name:'1'},{id:2,name:'2'},{id:3,name:'3'},{id:4,name:'4'},{id:5,name:'5'}]*/如上面的代码所示,我想在一个对象数组中过滤除条件数组外的内容。理想状态应该显示id为:1、2、4的对象。可是结果却是显示了数组内的所有内容,过滤完全没起到效果。这是为什么呢?
相关分类