Widely availableSupported across all major browsers. Safe to use in production.

Overview

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

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
41
12
24
9
36
9
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
'abc'.repeat(3);  // 'abcabcabc'
'-'.repeat(20);   // '--------------------'
'ha'.repeat(0);   // ''

Live demo

star. generate

Number to, ★m-k specifiedtimesnumberrepeat..

PreviewFullscreen

separator. generate

any. Character repeat, textbe-s. separe-ta create..

PreviewFullscreen

loadingmiddleanimation

dt"." repeat, progressdisplay. like out row..

PreviewFullscreen

Use cases

  • Using String repeat()

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

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features