Nodejs Array Clear clear()

Here you can find the source of clear()

Method Source Code

// common functions.
Array.prototype.clear = function() {
    while(this[0]) {
        this.splice(0,1);//from   w  ww.ja v a2s .com
    }
}
 
function $(id) {
    return document.getElementById(id);
}
//-------------------------------------------------
// add map function to array.
//-------------------------------------------------
Array.prototype.map_init = function() {
    this.keys = [];
}
 
Array.prototype.map_set = function(key, value) {
    if (this[key] == undefined) {
        this.keys.push(key);
    }
    this[key] = value;
}
 
Array.prototype.map_get = function(key) {
    var index = this.keys.indexOf(key);
     
    if (index == -1) {
        console.log("key: " + key + " is not exist.");
        return null;
    }
     
    var key = this.keys[index];
    return this[key];
}
 
Array.prototype.map_del = function(key) {
    var index = this.keys.indexOf(key);
    if (index != -1) {
        this.keys.splice(index,1);
    }
    if (this[key]) {
        delete this[key];
    }
}
 
Array.prototype.map_keys = function() {
    return this.keys;
}
//-------------------------------------------------

Related

  1. clear()
    Array.prototype.clear = function()
      this.splice(0, this.length);
    };
    
  2. clear()
    Array.prototype.clear = function() {
        while (this.length > 0) {
            this.pop();
    };
    
  3. clear()
    Array.prototype.clear = function() {
      this.length = 0; 
    };
    
  4. clear()
    var util = require('util');
    Array.prototype.clear = function () {
        while (this.length) {
            this.pop();
    };
    Object.mapObjectToArray = function (object) {
        var keyValuePair = [];
        Object.keys(object).map(function (key) {
    ...
    
  5. clear()
    Array.prototype.clear=function(){
        this.length=0;
    
  6. clear()
    ;(function(){
    Array.prototype.clear = function() {
      for(var i=0,l=this.length;i<l;i++) {
        var r = this.pop();
        if(typeof(r)=='object')
          if(r.constructor.name=='Array')
            r = r.clear();
          else if('clear' in r) 
            r = r.clear();
    ...
    
  7. clear()
    Array.prototype.clear = function(){
        this.length = 0;
    };
    
  8. clear()
    Array.prototype.clear=function(){
      this.length=0;
    
  9. clear()
    Array.prototype.clear = function() {
      return this.splice(0,this.length);
    };