技术解析

数组去重
0
2021-08-27 11:01:15
idczone

数组去重

 Array.prototype.unique1 = function () {
   var n = []; //一个新的临时数组
   for (var i = 0; i < this.length; i++) //遍历当前数组
   {
     if (n.indexOf(this[i]) == -1) n.push(this[i]);
   }
   return n
}

?

这代码是在养蛊啊!

``` js
Array.from(new Set(inputArray));
```

发出去的文章不能修改的吗?

+1

ES6 就是如此简单,不过面试老喜欢问这个问题,要如何回答才能显得高级呢
数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服