JavaScript (ES2026) reference · String Methods
JavaScript String repeat() Method
Return a new string made of this string repeated a given number of times, for example to build separators or padding.
JavaScript (ES2026) Since ES2015
Syntax
string.repeat(count)
Parameters
| Parameter | Description |
|---|---|
count |
How many copies, from 0. |
Return value
A new string.
Examples
console.log("ab".repeat(3), JSON.stringify("x".repeat(0)));
Output
ababab ""
const title = "Report";
console.log(title);
console.log("=".repeat(title.length));
Output
Report ======
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
str_repeat()· PHP
Related
string.padStart()· Pad the start of a string until it reaches a target length, for example zero-padding numbers like 007.string.concat()· Join one or more strings to the end of this string and return the result. The + operator and template literals are more common.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial