I have an array of objects.
const arr = [
{ title: \"sky\", artist: \"Jon\", id: 1 },
{ title: \"rain\", artist: \"Paul\", id: 2 },
{ title: \"sky\", artis
If you know the title
, artist
, id
are gonna be in the same order in each of the object, one solution can be this:
var arrayX=[
{ title: "sky", artist: "Jon", id: 1 },
{ title: "rain", artist: "Paul", id: 2 },
{ title: "sky", artist: "Jon", id: 1 }
];
var newArray = arrayX.map(i=> JSON.stringify(i)); //stringify all the objects so as to compare them
var res = newArray.filter((elem, index)=>{
if(newArray.indexOf(elem) === newArray.lastIndexOf(elem)){
return elem //get only those elements whihc do not have dupes
}
});
var finalResult = res.map(i=>JSON.parse(i)); //parse the result to get the array of object
console.log(finalResult)