Repeat string - Node.js String

Node.js examples for String:Repeat

Description

Repeat string

Demo Code


(function () {/*from   w ww  .j av  a  2 s .  c  o  m*/
  if (!String.prototype.repeat) {
    String.prototype.repeat = function (times) {
      var repeatedString;
      if (!times) {
        times = 1;
      }
      repeatedString = "";

      for (var i = 0; i < times; i += 1) {
        repeatedString += String(this);
      }
      return repeatedString;
    };
  }
}());

Related Tutorials