Nodejs Array Unshift unshift(data)

Here you can find the source of unshift(data)

Method Source Code

Array.prototype.unshift = function(data) {
   for(var i = this.length; i > 0; i--) {
      this[i] = this[i-1];/* w  w  w. j a v a  2s.  c om*/
   }
   this[0] = data;
   return this.length;
};

Related

  1. unshift()
    Array.prototype.unshift = function(){
       [].splice.apply(this, [0, 0].concat([].slice.apply(arguments)));
       return this.length;
    };
    
  2. unshift(elem)
    Array.prototype.unshift = function(elem) {
      for (var i = this.length; i > 0; i--) {
        this[i] = this[i - 1];
      this[0] = elem;
      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);
    };