JavaScript String repeat() method

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);

Try it yourself

let text = "Hello world!";
let result = text.repeat(4);

Try it yourself

Syntax

string.repeat(count)

Parameter

Parameter Description
count Required. Quantity.

Return value

Type Description
String 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
Unterstützt Unterstützt Unterstützt Unterstützt Unterstützt

Internet Explorer 11 (oder frühere Versionen) unterstützt dies nicht repeat().

Verwandte Seiten

JavaScript-String

JavaScript-String-Methode

JavaScript-String-Suche