zoukankan      html  css  js  c++  java
  • js 合并两个数组,去除重复项,只留一个

        //It's merge arr1 and arr2 , delete the same element only leave one
        //It's only apdapter array. If object, no.
        //The sequence of the two array is not required.
        mergeArray:function (arr1, arr2){
      for (var i = 0 ; i < arr1.length ; i ++ ){
          for(var j = 0 ; j < arr2.length ; j ++ ){
           if (arr1[i] === arr2[j]){
             arr1.splice(i,1); //利用splice函数删除元素,从第i个位置,截取长度为1的元素
        }
          }
      }
      //alert(arr1.length)
      for(var i = 0; i <arr2.length; i++){
       arr1.push(arr2[i]);
      }
      return arr1;
     }

    另:前替是两个数组中的项没有重复,如果重复,将不能达到想要的效果

  • 相关阅读:
    bzoj2791
    poi2012完成
    bzoj2795
    bzoj2790
    spring cloud 学习资源
    hystrix学习
    idea live template
    intellij-maven-imports-have-broken-classpath
    springboot elk实时日志搭建
    idea author模板
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/1979916.html
Copyright © 2011-2022 走看看