Favorites

JavaScript String.prototype.repeat() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.repeat()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The repeat() method returns a new string with the original repeated a given number of times.

Description

The repeat() method builds a new string containing the given number of copies of the original, joined together. A count of 0 gives an empty string.

Non-integer counts are truncated, so repeat(2.9) gives two copies. A count so large that the result would exceed the maximum string length also throws a RangeError.

It's handy for simple text formatting, such as separator lines, indentation and star ratings, and for generating test data of a known size. For padding a string to a fixed length, padStart() and padEnd() work out how many characters are needed for you.

Syntax

string.repeat(count)

Parameters

  • countHow many times to repeat the string, 0 or more.

Return Value

A new string containing the given number of copies.

Exceptions

  • RangeErrorThrown if count is negative or infinite.

Example

console.log('ab'.repeat(3));
console.log('-'.repeat(20));
console.log('★'.repeat(4) + '☆'.repeat(1));

Browser Support

The following information will show you the current browser support for the String.prototype.repeat() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee