String.repeat() Repeat a string
Last updated: 2026-09-09
String.repeat() Repeat a string
repeat returns the string repeated count times.
| Category | Strings |
|---|---|
| ES version | ES2015 |
📝 Syntax
const repeated = str.repeat(count);
⚙️ Parameters
| count | Count from 0 to Infinity; 0 gives empty string. |
|---|
Returns:The repeated new string.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
==============================
- - - - -
ababab
💡 Tip repeat replaces the legacy Array(n+1).join trick.
⚠️ Warning repeat(-1) throws RangeError; repeat(0) gives empty string.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| String.repeat() | ✓ v57 | ✓ v15 | ✓ v48 | ✓ v10 | ✓ v44 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qrepeat(0) and repeat(-1)?
Arepeat(0) gives ''; repeat(-1) throws.
QLength limit?
ABounded by engine max string size.
QCan repeat replace loops?
AYes, and faster.