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 »
Description
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 since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
repeat()
is not supported in Internet Explorer.