Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

I have an object that contains an array of objects

things = new Object(); 

things.thing = new Array();

 things.thing.push({place:"here",name:"stuff"}); 

things.thing.push({place:"there",name:"morestuff"});

 things.thing.push({place:"there",name:"morestuff"});

Can somebody tell me how to remove duplicate objects from an array?

1 Answer

0 votes
by (13.1k points)

You can do like this:

var obj = {};

for ( var i=0, len=things.thing.length; i < len; i++ )

      obj[things.thing[i]['place']] = things.thing[i];

 things.thing = new Array(); 

for ( var key in obj )

   things.thing.push(obj[key]);

Want to be a web developer? Check out the full stack developer course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...