es6 数组对象去重

let arr =[
    {
        name:'zhangsan',
        age:34
    },{
        name:'lisi',
        age:34
    },{
        name:'zhangsan',
        age:34
    },{
        name:'lisi',
        age:34
    },{
        name:'zhangsan',
        age:34
    },{
        name:'lisi',
        age:34
    }
]

let nArr = arr.filter((element,index,self)=>{
    return self.findIndex(x=>x.name===element.name) === index
})
console.log(nArr)

你可能感兴趣的:(JavaScript)