let a1 = [{rmName:'王五'},{rmName:'李四'},{rmName:'张三'},{rmName:'赵六'}]; let b2 = [{name:'王五'},{name:'李四'}]; // 结果:得到a1中除去b2中值的其他数据 // 方法一:forEach let filterA1 = a1.filter(item=>{ let flag = b2.findIndex(item_=>item_.name==item.rmName); return flag==-1?true:false }) console.log(filterA1) //[{"rmName": "张三"},{"rmName": "赵六"}]
// 方法二:every检测数组中每个元素是否 都满足所给条件,不满足就返回false let filterA1 = a1.filter(item=>{ return b2.every(item_=>{ return item_.name!=item.rmName }) }) console.log(filterA1) //[{"rmName": "张三"},{"rmName": "赵六"}]
标签:a1,两个,b2,rmName,filterA1,item,过滤,let,数组 From: https://www.cnblogs.com/lisir-blogshare/p/17916067.html