.repeat()

christian.dinh2481 total contributions
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:
All contributors
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor51 total contributions
- mehboobali986 total contributions
- christian.dinh
- Anonymous contributor
- Anonymous contributor
- mehboobali98
Looking to contribute?
- 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.