Javascript String times(number)

Description

Javascript String times(number)


'use strict'/*from w ww. j a v  a2s.c  o m*/

/*
 Define the times method for the String objects, which receives a number and returns the string repeated that number of
 times:

 */

String.prototype.times = function (number) {
  var i = 0;
  var output = []
  for (i; i < number; i++) {
    output.push(this);
  }
  return output.join('');
}



PreviousNext

Related