Nodejs Array Unshift unshift(elem)

Here you can find the source of unshift(elem)

Method Source Code

Array.prototype.unshift = function(elem) {
   for (var i = this.length; i > 0; i--) {
      this[i] = this[i - 1];//from   w  ww .java 2  s  . co  m
   }
   this[0] = elem;
   
   return ++this.length;
};

Related

  1. unshift()
    Array.prototype.unshift = function(){
       [].splice.apply(this, [0, 0].concat([].slice.apply(arguments)));
       return this.length;
    };
    
  2. unshift(data)
    Array.prototype.unshift = function(data) {
      for(var i = this.length; i > 0; i--) {
        this[i] = this[i-1];
      this[0] = data;
      return this.length;
    };
    
  3. unshiftMe(num)
    Array.prototype.unshiftMe = function (num) {
      this[this.length] = this[this.length-1];
      for (var i = this.length-1; i >= 1; i--) {
        this[i] = this[i-1];
      this[0] = num;
      return this.length;
    
  4. unshiftRange(arr)
    Array.prototype.unshiftRange = function(arr) {
        this.unshift.apply(this, arr);
    };