zoukankan      html  css  js  c++  java
  • js数组去重方法

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <body>
     8     <script type="text/javascript">
     9     var res = new Array(1,8,9,3,5,4,6,2,7,8,3,2,5,'a','a');
    10         Array.prototype.quchong = function(){
    11         var a = [this[0]];
    12         for(i = 1;i < this.length;i++)
    13         {
    14             var flag = true;
    15             for(j = 0;j < a.length;j++)
    16             {
    17                 if(this[i]==a[j])
    18                 {
    19                     flag = false;
    20                     break;
    21                 }
    22             }
    23             if(flag)
    24             {
    25                 a.push(this[i]);
    26             }
    27         }
    28         return a;
    29     }    
    30     alert(res.quchong());
    31     </script>
    32 </body>
    33 </html>

    有写的不妥当的地方,请留言指点一下。谢谢。

  • 相关阅读:
    django学习笔记1
    排序多重排序
    06计算列
    填充日期序列
    行,列单元格
    读取excel文件
    监控文本
    天干地支纪年法
    Mysql基础
    JDBC基础
  • 原文地址:https://www.cnblogs.com/hegaiying/p/5918644.html
Copyright © 2011-2022 走看看