js数组操作

 1 /*
 2 * 拓展数组原型方法
 3 */
 4 Array.prototype.contains = function (arr){
 5   for(var i=0;i<this.length;i++){
 6    if(this[i] == arr){
 7      return true;
 8     }
 9   }
10   return false;
11 }
12 
13 Array.prototype.indexOf = function(el){
14   for (var i=0,n=this.length; i<n; i++){
15     if (this[i] === el){
16       return i;
17      }
18     }
19   return -1;
20 }

 

posted @ 2014-08-22 15:54  未来动力  阅读(124)  评论(0编辑  收藏  举报