小结

作者: 李奕锦liyijin | 来源:发表于2021-07-21 09:59 被阅读0次

数组去重

1.Set

function dup(arr) {
  return Array.from(new Set(arr));
}
let arr = [1, 2, 2, 3, 3, undefined, undefined, NaN, NaN, 8, 8, 9];
console.log(dup(arr));

2.Map filter has set

let arr1 = [9,9,2,2,1]
function unique(arr){
   const res=new Map();
   return arr.filter((a)=> !res.has(a) && res.set(a,1))
}
console.log(unique(arr1))

// 你是谁构造的 你的原型就是谁的 prototype 属性对应的对象
// 对象.proto === 其构造函数.prototype

相关文章

网友评论

      本文标题:小结

      本文链接:https://www.haomeiwen.com/subject/oizdmltx.html