//最终结果
[{a:1,b:2},{a:'',b:2},{a:11},{a:11,b:''},{a:'',b:999},{b:132},{a:'',b:99},{a:'',b:90},{a:'',b:''},{a:''},{b:''},{a:1,b:''}] =>[ { a: 1, b: 2 }, { a: 11 }, { b: 132 } ]
方法1:
let a=[{a:1,b:2},{a:'',b:2},{a:11},{a:11,b:''},{a:'',b:999},{b:132},{a:'',b:99},{a:'',b:90},{a:'',b:''},{a:''},{b:''},{a:1,b:''}]
a.filter(item => !Object.values(item).includes(''))
方法2:
let a=[{a:1,b:2},{a:'',b:2},{a:11},{a:11,b:''},{a:'',b:999},{b:132},{a:'',b:99},{a:'',b:90},{a:'',b:''},{a:''},{b:''},{a:1,b:''}]
let b =[];
let d;
for (let index = 0; index < a.length; index++) {
for (const key in a[index]) {
if(a[index][key] === '') b.push(a[index])
}
}
d = [...a,...b]
function deWeight(arr) {
for (var i = 0; i < arr.length - 1; i++) {
for (var j = i+1; j < arr.length; j++) {
if (arr[i].a === arr[j].a ||arr[j].a ===''||arr[i].a ===''|| arr[i].b === arr[j].b || arr[j].b ===''|| arr[i].b ==='' ) {
arr.splice(j, 1);
j--;
}
}
}
return arr;
}
var newArr = deWeight(d);
console.log(newArr);