// 原数组
let objArray = [
{ name: "111", id: "1" },
{ name: "333", id: "3" },
{ name: "111", id: "2" },
{ name: "222", id: "3" },
];
function objSet(arr, prop) {
return arr.filter(function (item, index, self) {
return self.findIndex((el) => {
return el[prop] == item[prop]
}) === index;
});
}
function objSetMore(objArray) {
let arr = [...objArray];
Object.keys(objArray[0]).forEach((element) => {
arr = [...objSet(arr, element)];
});
return arr;
}
// 处理后数组
let obj = objSetMore(objArray);
console.log(obj, "obj");
标签:arr,return,name,对象,objArray,prop,数组,id,属性
From: https://www.cnblogs.com/bingquan1/p/17140603.html