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. 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().

Related Pages

JavaScript String

JavaScript String Methods

JavaScript String Search