0
点赞
收藏
分享

微信扫一扫

手写数组去重

东林梁 2022-04-13 阅读 52
前端
//数组去重
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()]
}
举报

相关推荐

数组去重

js数组去重

数组去重方法

Js数组去重

前端数组去重

对象数组去重

Set数组去重

indexOf数组去重

0 条评论