Repeat a string

suggest change

This can be done using the .repeat() method:

"abc".repeat(3);  // Returns "abcabcabc"
"abc".repeat(0);  // Returns ""
"abc".repeat(-1); // Throws a RangeError

In the general case, this should be done using a correct polyfill for the ES6 String.prototype.repeat() method. Otherwise, the idiom new Array(n + 1).join(myString) can repeat n times the string myString:

var myString = "abc";
var n = 3;

new Array(n + 1).join(myString);  // Returns "abcabcabc"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Strings:
* Syntax
* Repeat a string

Table Of Contents
8 Strings
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde