function duplicateRemovalArr (arr, key) {
let hash = {};
let result = arr.reduce((total, currentValue) => {
if (!hash[currentValue[key]]) {
hash[currentValue[key]]= true;
total.push(currentValue);
}
return total;
},[]);
return result;
}
示例如下:
let arr = [{id:1,name:'小明'},{id:1,name:'小南'},{id:3,name:'小明'}]
根据对象属性name去重
duplicateRemovalArr (arr,'name')
执行结果如下:
执行结果.png
网友评论