String repeat()
The repeat() method of strings returns the original string repeated a number of times.
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
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.
Related links
Powered by web-features