数组类似于这样的结构:
const arr = [
{
name:'tom',
age:15
},
{
name:'jack',
age:18
},
{
name:'tom',
age:10
}
现在需要把name重复的剔除。
1. ES6的Set
2.reduce
var hash = {};
arr = arr.reduce(function(item, next) {
hash[next.name] ? '' : hash[next.name] = true && item.push(next);
return item
}, [])
本文介绍了一种使用ES6 Set和reduce方法去除JavaScript数组中重复元素的方法,特别针对对象数组中name属性重复的情况。
463





