Nodejs Array Repeat repeat(num)

Here you can find the source of repeat(num)

Method Source Code

Array.prototype.repeat = function(num) {
   var self = this;
   for (var i = 0; i < num; i++) {
      self = self.concat(self);
   }/* w  w  w.  j av a  2  s . c  o m*/
   return self;
}

var arr = [1, 2, 3];
var ary = arr.repeat(1);
console.log(ary); // [ 1, 2, 3, 1, 2, 3 ]

Related

  1. repeat(reps)
    Array.prototype.repeat = function(reps) {
      var copy = this.clone()
      for (var i = 0; i < reps; i++) copy.push.apply(copy, copy)
      return copy
    
  2. repeat_element(element)
    Array.prototype.repeat_element = function(element)
         var repeat = false;
         for (i=0;i<this.length;i++)
             if(element==this[i])
                 repeat = true;
         return repeat;
    ...