jquery - Javascript remove duplicated object from array -


i'm having trouble remove duplicated object array

example:

var list = [{place:"aaa",name:"me"}, {place:"bbb",name:"you"}, {place:"aaa",name:"him"}]; 

in example have 3 objects, , want remove object have duplicated place

as added:

i want remove one, dont matter wich 1

if want remove duplicated items , keep first occcurence of particular place, can use simple loop re-create new array input:

var list = [{place:"aaa",name:"me"}, {place:"bbb",name:"you"}, {place:"aaa",name:"him"}];  var uniqplace = function(array){     var result = [];     array.foreach(function(el){         if (result.filter(function(n){ return n.place === el.place }).length==0){             result.push(el);         }     })     return result; } 

output:

uniqplace(list); 

[{"place":"aaa","name":"me"},{"place":"bbb","name":"you"}]


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -