一行代码实现数组去重
Set· : let newArr = [...new Set([1,2,3,1,'a',1,'a'])]
filter·: let newArr = arr.filter( (val, index, self) => {return self.indexOf(val) == index;})
常规的数组去重:
var arr = [1,35,1,45,2,4,65,3,3,4,5,6,6,6];
function
unique1(arr){
var temp = [];
var hash = {};
for(var i=0,len=arr.length; i<len; i++){
if (!hash[arr[i]]){
temp.push(arr[i]);
hash[arr[i]] = true ;
}
}
return
temp;
}