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);

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2022-02-22
  • 2022-02-11
猜你喜欢
  • 2022-01-17
  • 2021-12-04
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案