| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since September 2015.
The repeat() method of String values constructs and returns a new string
which contains the specified number of copies of this string, concatenated together.
const mood = "Happy! ";
console.log(`I feel ${mood.repeat(3)}`);
// Expected output: "I feel Happy! Happy! Happy! "
repeat(count)
A new string containing the specified number of copies of the given string.
RangeErrorThrown if count is negative or if count overflows maximum string length.
"abc".repeat(-1); // RangeError
"abc".repeat(0); // ''
"abc".repeat(1); // 'abc'
"abc".repeat(2); // 'abcabc'
"abc".repeat(3.5); // 'abcabcabc' (count will be converted to integer)
"abc".repeat(1 / 0); // RangeError
({ toString: () => "abc", repeat: String.prototype.repeat }).repeat(2);
// 'abcabc' (repeat() is a generic method)
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.repeat |
String.prototype.repeat in core-jsString.prototype.repeatString.prototype.concat()This page was last modified on Jul 10, 2025 by MDN contributors.
Stringanchor()at()big()blink()bold()charAt()charCodeAt()codePointAt()concat()endsWith()fixed()fontcolor()fontsize()includes()indexOf()isWellFormed()italics()lastIndexOf()link()localeCompare()match()matchAll()normalize()padEnd()padStart()repeat()replace()replaceAll()search()slice()small()split()startsWith()strike()sub()substr()substring()sup()toLocaleLowerCase()toLocaleUpperCase()toLowerCase()toString()toUpperCase()toWellFormed()trim()trimEnd()trimStart()valueOf()[Symbol.iterator]()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |