js remove duplicates from array by property code example
Example 1: filter duplicate value in array of object typescript
var arrOfObj = [
{
id:1 ,name:'abc',age:27
},
{
id:2 ,name:'pqr',age:27
},
{
id:1 ,name:'abc',age:27
},
]
var setObj = new Set();
var result = arrOfObj.reduce((acc,item)=>{
if(!setObj.has(item.age)){
setObj.add(item.age)
acc.push(item)
}
return acc;
},[]);
console.log(result);
Example 2: remove duplicates from array of objects javascript
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)