我從我的Web服務中獲得這種列表。我想,以消除重複的用戶名:如何從列表中刪除重複
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
}];
是否有一個功能,可以讓我刪除重複值(要素之一= Plr1)?
使用一個循環來創建一個新的陣列或接頭(http://www.w3schools.com/jsref/jsref_splice.asp)項 – x4rf41 2013-05-03 10:59:47
此鏈接可以對你有所幫助: http://stackoverflow.com/questions/8786197/remove-duplicates-from-an-array-which-contains-array – 2013-05-03 11:00:27
['_.uniq(Mylist,function(x){return x.username})']( http://underscorejs.org/) – georg 2013-05-03 12:34:24