Javascript Array clear()

Description

Javascript Array clear()


/**//from   w  w w  . j a v  a2 s.  com
 *  Array#clear() -> Array
 *
 *  Clears the array (makes it empty) and returns the array reference.
 *
 *  ##### Example
 *
 *      var guys = ['Sam', 'Justin', 'Andrew', 'Dan'];
 *      guys.clear();
 *      // -> []
 *      guys
 *      // -> []
**/
Array.prototype.clear = function() {
  this.length = 0;
  return this;
};

Javascript Array clear()

Array.prototype.clear = function () {
 return this.splice( 0, this.length );
};

Javascript Array clearArray()


Array.prototype.clearArray = function(){
    while(this.length) this.pop();
};



PreviousNext

Related