JavaScript String repeat()
Examples
Create copies of a text:
let text = "Hello world!";
let result = text.repeat(2);
Try it Yourself »
let text = "Hello world!";
let result = text.repeat(4);
Try it Yourself »
Definition and Usage
The repeat()
method returns a string with a number of copies of a string.
The repeat()
method returns a new string.
The repeat()
method does not change the original string.
Syntax
string.repeat(count)
Parameters
Parameter | Description |
count | Required. The number of copies. |
Return Value
Type | Description |
A string | The copies of the original string. |
Browser Support
repeat()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
repeat()
is not supported in Internet Explorer 11 (or earlier).