let arr = [
{
id: 1,
name: '张三',
hobby: "抽烟,喝酒,烫头"
},
{
id: 2,
name: '李四',
hobby: "打麻将,蹦迪,烫头"
},
{
id: 3,
name: '张三',
hobby: "敲代码,打羽毛球"
},
{
id: 4,
name: '王五',
hobby: "做饭,烫头"
}
]
let middleArr = {}
let result = arr.reduce((count, cur) => {
middleArr[cur.name] ? null : middleArr[cur.name] = count.push(cur)
return count
}, [])
console.log(result)
标签:cur,累加器,reduce,数组,烫头,hobby,id,name
From: https://www.cnblogs.com/orangeczs/p/17117304.html