I have an array of objects.
const arr = [
{ title: \"sky\", artist: \"Jon\", id: 1 },
{ title: \"rain\", artist: \"Paul\", id: 2 },
{ title: \"sky\", artis
That's a one-liner:
list.filter(el => list.filter(e => e.title == el.title).length == 1);
const arr = [{
title: "sky",
artist: "Jon",
id: 1
},
{
title: "rain",
artist: "Paul",
id: 2
},
{
title: "sky",
artist: "Jon",
id: 1
}
];
const arr1 = [{
title: "sky",
artist: "Jon",
id: 1
},
{
title: "rain",
artist: "Paul",
id: 2
},
{
title: "sky",
artist: "Jon",
id: 1
},
{
title: "rain",
artist: "Paul",
id: 2
}
];
function removeDupes(list) {
return list.filter(el => list.filter(e => e.id == el.id).length == 1);
}
console.log(removeDupes(arr));
console.log(removeDupes(arr1));