Create an array with same element repeated multiple times
In ES6 using Array fill() method console.log( Array(5).fill(2) ) //=> [2, 2, 2, 2, 2]
In ES6 using Array fill() method console.log( Array(5).fill(2) ) //=> [2, 2, 2, 2, 2]
These days, the repeat string method is implemented almost everywhere. (It is not in Internet Explorer.) So unless you need to support older browsers, you can simply write: “a”.repeat(10) Before repeat, we used this hack: Array(11).join(“a”) // create string with 10 a’s: “aaaaaaaaaa” (Note that an array of length 11 gets you only 10 “a”s, … Read more