To create a zero filled JavaScript array, we use the fill
method.
For instance, we write
const arr = Array(10).fill(0);
to call Array
with 10 to create an array with 10 empty slots.
Then we call fill
with 0 to fill all the empty slots with 0.