.repeat()
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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.