js中Array自定义contains, indexOf, delete方法.

时间:2014-01-21 16:40:36   收藏:0   阅读:501

Array.prototype.contains = function (elem) {    for (var i = 0; i < this.length; i++) {             if (this[i] == elem) {                     return true;             }       }      return false; }

 

 

 

Array.prototype.indexOf = function(o){   

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

           if(this[i] == o){

                            return i;

           }           return -1;     } };

 

 

Array.prototype.delete = function(o){

   var index = this.indexOf(o);

           if(index != -1){

                 this.splice(index,1)

             }

           return this;

}

原文:http://www.cnblogs.com/dancser/p/3527366.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!