JavaScript String repeat() method
Example
Repeat the string "Runoob" twice:
var
str
=
"
Runoob
"
;
str
.
repeat
(
2
)
;
n Output result:
RunoobRunoob
Try it »
Definition and Usage
The repeat() method copies a string a specified number of times.
Browser support
The numbers in the table indicate the first browser version that supports this property.
| Method | |||||
|---|---|---|---|---|---|
| repeat() | 41 | 12.0 | 24.0 | 9 | 28 |
Syntax
string.repeat(count)
Parameter value
| Parameters | Description |
|---|---|
| count | Required. The number of times to copy the string. |
Return Value
| Type | Description |
|---|---|
| String |
Returns the string copied the specified number of times and concatenated together. |
Technical Details
| JavaScript version: | ECMAScript 6 |
|---|
JavaScript String object