1 回答
TA贡献1777条经验 获得超3个赞
您可以使用地图和过滤器的组合
var dept =[{"department": [{ "userName": "cds","userId": "33","userFirstname": "Chef","userLastname": "Jone"},{"userName": "asset1","userId": "27","userFirstname": "Asset","userLastname": "Ann "}],"comment": "","doc": null},{ "department": [{ "userName": "audit1","userId": "32","userFirstname": "Audit","userLastname": "Kim"},{ "userName": "cds","userId": "33","userFirstname": "Chef","userLastname": "Jone"}],"comment": "","doc": null}];
let tracker = {}
let op = dept.map(val => {
let department = val.department
let filtered = department.filter(({userId}) => {
if(tracker[userId] !== undefined ){
return false
} else {
tracker[userId] = userId
return true
}
})
return {...val,department: filtered}
})
console.log(op)
添加回答
举报