js数组去重


		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;
		}

posted @ 2019-01-03 12:10  sfornt  阅读(135)  评论(0编辑  收藏  举报