JavaScript String repeat() method
- Previous Page prototype
- Next Page replace()
- Go to Parent Directory JavaScript String Reference Manual
Definition and usage
repeat()
The method returns a string with multiple copies of the string.
repeat()
The method returns a new string without changing the original string.
Instance
Create a copy of the text:
let text = "Hello world!"; let result = text.repeat(2);
let text = "Hello world!"; let result = text.repeat(4);
Syntax
string.repeat(count)
Parameter
Parameter | Description |
---|---|
count | Required. Number of copies. |
Return value
Type | Description |
---|---|
String | A copy of the original string. |
Browser support
repeat()
Is ECMAScript6 (ES6) feature.
All browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supported | Supported | Supported | Supported | Supported |
Internet Explorer 11 (or earlier versions) does not support repeat()
.
- Previous Page prototype
- Next Page replace()
- Go to Parent Directory JavaScript String Reference Manual