js 数组去重

使用map的不重复性进行去重 

		unique:function(arr){
			// return Array.from(new Set(arr));
			var map = new Map();
			var array = new Array();
			for(var i  = 0 ; i < arr.length;i++){
				if(map.has(arr[i].key)){
					map.set[arr[i].key,true];
				}else{
					map.set(arr[i].key,false);
					array.push(arr[i]);
				}
			}
			return array;
		},

?mid=&wid=51824&sid=&tid=8555&rid=LOADED&custom1=mp.csdn.net&custom2=%2Fpostedit&t=1571108089437?mid=&wid=51824&sid=&tid=8555&rid=FINISHED&custom1=mp.csdn.net&t=1571108089437

posted @ 2021-03-08 17:16  linhuang  阅读(1)  评论(0编辑  收藏  举报  来源