Sometimes, we want to create empty array of a given size with JavaScript.
In this article, we’ll look at how to create empty array of a given size with JavaScript.
How to create empty array of a given size with JavaScript?
To create empty array of a given size with JavaScript, we use the Array
constructor.
For instance, we write
const arr = Array(5);
console.log(arr.length);
to call Array
with 5 to return an array with 5 empty slots.
Conclusion
To create empty array of a given size with JavaScript, we use the Array
constructor.