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

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

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -