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 »
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.
string.repeat(
count)
Parameter | Description |
count | Required. The number of copies. |
Type | Description |
A string | The copies of the original string. |
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).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!