var arr2 = [
{ name: "name1", num: "1" },
{ name: "name2", num: "11" },
{ name: "name3", num: "12" },
{ name: "name4", num: "13" },
{ name: "name2", num: "1" },
{ name: "name6", num: "12" }
]
function arrayUnique2(arr, name) {
var hash = {};
return arr.reduce(function (item, next) {
hash[next[name]] ? '' : hash[next[name]] = true && item.push(next);
return item;
}, []);
}
console.log(arrayUnique2(arr2, "name"));
console.log(arrayUnique2(arr2, "num"));
数组去重封装函数(根据数组中对象属性的值)
最新推荐文章于 2024-08-21 14:09:37 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)