JavaScript repeat() Method

JavaScript repeat() Method returns a string with number of copies of original string.

For example if we have a string we can make it's copies using repeat() method. This will create a new string with 2 copies of our original string.

var string1 = 'HowToCodeSchool';
var string2 = string1.repeat(2);
document.getElementById('demo').innerHTML = 'Output: ' + string2;

Output: HowToCodeSchoolHowToCodeSchool

Similarly this will create 3 copies of our main string.

var string1 = 'HowToCodeSchool';
var string2 = string1.repeat(3);
document.getElementById('demo').innerHTML = 'Output: ' + string2;

Output: HowToCodeSchoolHowToCodeSchoolHowToCodeSchool

Video Tutorial

Watch video tutorial on JavaScript repeat() Method.