Javascript Array remove( item ) method

Description

Javascript Array remove( item ) method


Array.prototype.remove = function( item ) {
  var index = this.indexOf( item );
  if ( index > -1 ) {
    this.splice( index, 1 );//w w  w  .ja  v  a 2 s .  c o  m
  }
  return this;
};

Javascript Array remove( item )

Array.prototype.remove = function ( item ) {
 var self = this;
 var index = self.indexOf( item );

 if( index > -1 ) {
  return self.splice( index, 1 )[ 0 ];
 }

 return null;/*from   w ww. j  a  v a  2  s  .  c o  m*/
};



PreviousNext

Related