How to Repeat a String in JavaScript
Here are two ways to create a string repeating a specific text in JavaScript.
repeat()
The simplest way to create a new string repeating a text is to use the repeat() string method.
The repeat() method returns a new string containing the specified number of copies of the given text.
Below is an example.
'Apple'.repeat(3);
//AppleAppleApple
fill()
There is also an old way of achieving the same result by first creating an array of the needed size, fill in the default va...
Published on April 16, 2021 04:19