.repeat()
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.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours