To create a string of variable length, filled with a repeated character with JavaScript, we call the array join
method.
For instance, we write
const str = new Array(len + 1).join(character);
to create an array with length len + 1
with Array
.
And then we call join
with character
to return a string filled with character
of length len
.