Javascript Array removeByIndex(index)

Description

Javascript Array removeByIndex(index)



Array.prototype.removeByIndex = function (index) {
    this.splice(index,1);//w w w.  ja  v  a2 s  .c  om
};

Javascript Array removeByIndex(index)

Array.prototype.removeByIndex = function(index){
 var i=0,n=0;/* w  w  w.  j a v  a2  s  .c  o m*/
 for(i=0;i<this.length;i++){
  if(this[i]!=this[index]){
   this[n++]=this[i];
  }
 }
 if(n<i){
  this.length = n;
 }
};

Javascript Array removeByIndex(index)

Array.prototype.removeByIndex = function(index){
 // body... /*from w  ww. j  a  v  a 2 s. c  om*/
 var i=0,n=0;
 // var arrSize=this.length;
 for(i=0;i<this.length;i++){
  if(this[i]!=this[index]){
   this[n++]=this[i];
  }
 }
 if(n<i){
  this.length=n;
 }
};



PreviousNext

Related