.repeat()

Anonymous contributor's avatar
Anonymous contributor
Published Jun 21, 2021Updated Jun 19, 2023
Contribute to Docs

The .repeat() string method repeats a string a specified number of times. String will be concatenated.

Syntax

string.repeat(count);

count is an number between 0 and Infinity, indicating the number of times to repeat a string. If the number is a decimal value, it is rounded down to the nearest integer.

Example

Repeating a string a specified number of times:

console.log('Berlin is my favorite city! '.repeat(2));
// Output: Berlin is my favorite city! Berlin is my favorite city!

Codebyte Example

The following is runnable, and demonstrates the use of the .repeat() method:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy