.repeat()

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

Syntax

Loading...

count is an integer between 0 and Infinity, indicating the number of times to repeat a string.

Example 1

Repeating a string a specified number of times:

Loading...

Example 2

Repeating a string a specified number of times using a decimal:

Loading...

The decimal will be converted to an integer. So in this case, 3.5 becomes 3.

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn JavaScript on Codecademy