javascript - How can I remove duplication from list -


i have kind of list web service. want eliminate username duplication:

mylist = [{     "username": "plr1",     "is_online": true,     "email": null,     "message": null,     "direction": 1,     "image_url": "" }, {     "username": "plr2",     "is_online": false,     "email": "",     "message": null,     "direction": 1,     "image_url": "" }, {     "username": "plr1",     "is_online": false,     "email": "",     "message": null,     "direction": 1,     "image_url": null }]; 

is there function allows me remove duplicated values (one of elements=plr1)?

demo: http://jsfiddle.net/abc123/zgybb/

note: last loop show items removed , left in array.

js:

var mylist= [{"username":"plr1","is_online":true,"email":null,"message":null,"direction":1,"image_url":""},{"username":"plr2","is_online":false,"email":"","message":null,"direction":1,"image_url":""},{"username":"plr1","is_online":false,"email":"","message":null,"direction":1,"image_url":null} ];  (var = 0; < mylist.length; i++) {     for(var j = + 1; j < mylist.length; j++) {         if(mylist[i].username.tolowercase() == mylist[j].username.tolowercase())             mylist.splice(j, 1);     } }  //not needed proof items removed. (var = 0; < mylist.length; i++) {    alert(mylist[i].username); } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -