How to create an array of empty strings with JavaScript?

Sometimes, we want to create an array of empty strings with JavaScript.

In this article, we’ll look at how to create an array of empty strings with JavaScript.

How to create an array of empty strings with JavaScript?

To create an array of empty strings with JavaScript, we can use the Array function and the fill method.

For instance, we write:

const arr = Array(20).fill("");
console.log(arr)

to create an array with 20 empty slots with Array(20).

Then we call fill with an empty string to fill the empty slots with empty strings.

Therefore, arr is an array with 20 empty strings.

Conclusion

To create an array of empty strings with JavaScript, we can use the Array function and the fill method.