• javascript for in 循环时,会取到Array.prototype


    /**
     *删除数组指定下标或指定对象
     */
    
    if(!Array.prototype.remove){
    
        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;
                }
            }
        }
    }
    
    
    //get array size
    if(!Array.prototype.countArray){
    
        Array.prototype.countArray=function(){
            if(this == null){
                return 0;
            }
            var size = 0;
            for(var key in this){
                if(this[key] != undefined && typeof this[key] != 'function'){
                    size++;
                }
            }
            return size;
        }
    }

    在JS中,扩展了array的两个方法,在for in 会输出CountArray和remove这个元素,

    目前使用类似

    for(var key in array){
      if(typeof array[key] == 'function'){
       continue;
      }
      // do somthing
    }
  • 相关阅读:
    【CF989E】A Trance of Nightfall
    [SHOI2012]信用卡凸包
    [HNOI2016]最小公倍数
    [HNOI2012]射箭
    [SCOI2015]小凸想跑步
    [CQOI2006]凸多边形
    ### Hadoop
    ### awk
    ### Theano
    ### Python Learning
  • 原文地址:https://www.cnblogs.com/fsong/p/5135511.html
Copyright © 2020-2023  润新知