zoukankan      html  css  js  c++  java
  • 获取JS数组中所有重复元素

    //获取数组内所有重复元素,并以数组返回

    //例:入参数组['1','2','4','7','1','2','2'] 返回数组:['1','2']

    function GetRepeatFwxmmc(ary1){

      var ary = ary1.sort();//数组排序

      var cffwxmsAry = new Array();

      //所有重复元素添加进新数组内

      for(var i=0;i<ary.length;i++){

        if (ary[i]==ary[i+1]){

          cffwxmsAry.push(ary[i]);

        }

      }

      var result = [], isRepeated;

      //对重复元素数组进行元素去重

      for (var k = 0; k < cffwxmsAry.length; k++) {

        isRepeated = false;

        for (var j = 0;j < result.length; j++) {

          if (cffwxmsAry[k] == result[j]) {

            isRepeated = true; break;

          }

        }

        if (!isRepeated) {

          result.push(cffwxmsAry[k]);

        }

      }

      return result;

    }

  • 相关阅读:
    Document
    Document
    Document
    Document
    Document
    Document
    Document
    Document
    C#中的委托是什么
    C# Lambda表达式Contains方法 like
  • 原文地址:https://www.cnblogs.com/RoyalBlue/p/7116508.html
Copyright © 2011-2022 走看看