let arr1 = [{
name: "wzf",
sex: "nan",
"00000",
},
{
name: "wzf",
sex: "nan",
"gfd",
},
{
name: "wzf",
sex: "3234",
"34567",
},
{
name: "hgfdgnm",
sex: "narryttyn",
"34567",
}
];
//对象型数组去重
function deWeight(arr, ...arguements) {
// console.log(arguements);//获得需要去重的字段数组
function getBoolean(o, m) {
let list = arguements.map(x => o[x] == m[x]); //值均为布尔
return list.every(i => i); //要使这些布尔值都真才能满足条件,因为要求的条件是 并且
}
let result = [];//新数组
//总数组与新数组比较,遍历总数组时用新数组的some方法进行判断
arr.map(o => !result.some(m => getBoolean(o, m)) ? result.push(o) : '');
return result;
}
let resultArr = deWeight(arr1, 'name', 'sex'); //指定需要按哪些字段去重,支持按多个字段去重
console.log(resultArr);