//数组去重
const a=['天',1,2,5,,'5',2,2,'5'];
const uniq=function(v){//最简方法 但是空值会变成undefined
return [...new Set(v)]
}
const uniq2=function(v){
let map=new Map();
for(let i=0;i<v.length;i++){
let number=v[i];
if(number==undefined) continue
if(map.has(number)){
continue
}else{
map.set(number,true)
}
}
return [...map.keys()]
}
手写数组去重
于 2022-04-10 01:24:20 首次发布