Array.prototype.removeIndex = function(i)
 {
   if (isNaN(i) || i > this.length)
      return false;
  this.splice(i,1);
 }
 
 Array.prototype.remove = function(key)
 {
  for (var i = 0; i < this.length; ++i)
  {
     if (this[i] == key)
         this.splice(i, 1);
  }

 }

 

   b = ['1','2','3','4','5'];
 alert("elements: "+b+"nLength: "+b.length);
 b.remove('4');       //删除值为'4'的元素
   b.removeIndex(3) //删除下标为1的元素
 alert("elements: "+b+"nLength: "+b.length);

posted on 2009-12-08 13:10  袁晓平  阅读(740)  评论(0编辑  收藏  举报