Sometimes, we want to create a string of variable length, filled with a repeated character with JavaScript.
In this article, we’ll look at how to create a string of variable length, filled with a repeated character with JavaScript.
How to create a string of variable length, filled with a repeated character with JavaScript?
To create a string of variable length, filled with a repeated character with JavaScript, we use the string repeat
method.
For instance, we write
const s = "X".repeat(10);
to call "X".repeat
with 10 to return a string with 'X'
repeated 10 times.
Conclusion
To create a string of variable length, filled with a repeated character with JavaScript, we use the string repeat
method.