filter to remove duplicated data in typescript code example
Example: filter duplicate value in 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(); // create key value pair from array of array
var result = arrOfObj.reduce((acc,item)=>{
if(!setObj.has(item.age)){
setObj.add(item.age)
acc.push(item)
}
return acc;
},[]);//converting back to array from mapobject
console.log(result);