String repeat()
The repeat() method of String values constructs and returns a new string which contains the specified number of copies of this string, concatenated together.
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 String values constructs and returns a new string
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.