coderef

String repeat()Baseline · Widely available

The repeat() method of strings returns the original string repeated a number of times.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Sep 30, 2015. Widely available since Mar 30, 2018.

Browser support

DesktopChrome
1–40Not supported
41+Supportedsince Mar 3, 2015
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–23Not supported
24+Supportedsince Sep 17, 2013
Current: 157
Safari
1–8Not supported
9+Supportedsince Sep 30, 2015
Current: 27
MobileChrome Android
18–35Not supported
36+Supportedsince Jul 16, 2014
Current: 155
Firefox Android
4–23Not supported
24+Supportedsince Sep 17, 2013
Current: 157
Safari iOS
1–8Not supported
9+Supportedsince Sep 16, 2015
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: repeat.

Feature detection

JS · check before using
if ("repeat" in String || ("prototype" in String && "repeat" in String.prototype)) {
  // String.repeat is available
}

Documentation (MDN)

Specification