How to add default array values with JavaScript?

To add default array values with JavaScript, we call the fill method.

For instance, we write

const arr = Array(100).fill(0);

to define an array with 100 empty slots with Array(100).

Then we call fill with 0 to fill the empty slots with 0’s.