Categories
JavaScript Answers

How to create a zero filled JavaScript array?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *