• Javascript根据指定下标或对象删除数组元素


    /**

    *删除数组指定下标或指定对象
    */
    Array.prototype.remove=function(obj){
    for(var i =0;i <this.length;i++){
    var temp = this[i];
    if(!isNaN(obj)){
    temp=i;
    }
    if(temp == obj){
    for(var j = i;j <this.length;j++){
    this[j]=this[j+1];
    }
    this.length = this.length-1;
    }
    }
    }
     
    删除数组某一项或几项

    1:js中的splice方法

      splice(index,len,[item])    注释:该方法会改变原始数组。

    splice有3个参数,它也可以用来替换/删除/添加数组内某一个或者几个值

    index:数组开始下标        len: 替换/删除的长度       item:替换的值,删除操作的话 item为空

    如:arr = ['a','b','c','d']

     
  • 相关阅读:
    记录我发现的第一个关于 Google 的 Bug
    iOS 中的 Delayed Transition
    Appstore|IPA
    地图|定位
    开发者账号
    App跳转
    国际化
    短信|彩信
    闪光灯
    Cornerstone|SVN
  • 原文地址:https://www.cnblogs.com/aisiqi-love/p/10174299.html
Copyright © 2020-2023  润新知