美文网首页
将数组中重复项删除

将数组中重复项删除

作者: 一名有马甲线的程序媛 | 来源:发表于2018-04-24 10:15 被阅读2次
    <script>
    Array.prototype.unique3 = function(){
     var res = [];
     var json = {};
     for(var i = 0; i < this.length; i++){
      if(!json[this[i]]){
       res.push(this[i]);
       json[this[i]] = 1;
      }
     }
     return res;
    }
    var arr = [112,112,34,'你好',112,112,34,'你好','str','str1'];
    alert(arr.unique3());
    </script>
    

    相关文章

      网友评论

          本文标题:将数组中重复项删除

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