标签:code pre lis 去重 var length fun splice ++
var list = [{id:1, name:'111'}, {id:2, name:'222'}, {id:2, name:'333'}];
function distinctListById(arr){
var tmp = {};
if(arr && arr.length){
for(var i = 0; i < arr.length; i++){
if(!tmp[arr[i].id]){
tmp[arr[i].id] = 1;
}else{
arr.splice(i, 1);
}
}
}
return arr;
}
标签:code pre lis 去重 var length fun splice ++
原文地址:https://www.cnblogs.com/lalalagq/p/10213521.html