复杂数组去重

    let arr = [3, 1, [1], 1, [1], true, true, {}, '1', NaN, undefined, NaN, undefined, {}, null, null]
    const set = new Set()
    const result = [...new Set(arr)].filter(item=>{
      if(typeof item !== 'object' || item === null){
        return true
      }else if(set.has(JSON.stringify(item))){
        return false
      }else{
        set.add(JSON.stringify(item))
        return true
      }
    })
    console.log(result)

 

posted @ 2021-02-24 18:19  Butter_Fly  阅读(52)  评论(0编辑  收藏  举报