Many array methods skip empty/uninitialized values ("sparse arrays"). Note that empty/uninitialized is a different state than an array entry containing a value undefined or null.
Array(5) // [empty × 5]
Array(5).fill(undefined) // [undefined, undefined, undefined, undefined, undefined]
Array(5).fill(null) // [null, null, null, null, null]
As other answers point out, you can use fill() to initialize all indices of your array if you want to run an array method like map() across all array indices.
Per MDN...
Array methods have different behaviors when encountering empty slots in sparse arrays. In general, older methods (e.g., forEach) treat empty slots differently from indices that contain undefined.
Methods that have special treatment for empty slots include the following: concat(), copyWithin(), every(), filter(), flat(), flatMap(), forEach(), indexOf(), lastIndexOf(), map(), reduce(), reduceRight(), reverse(), slice(), some(), sort(), and splice(). Iteration methods such as forEach don't visit empty slots at all. Other methods, such as concat, copyWithin, etc., preserve empty slots when doing the copying, so in the end the array is still sparse.
Example from the MDN reduce page...
The example illustrates how reduce treats undefined array values differently from empty/uninitialized values. i.e. the undefined value is not skipped and results in NaN whereas the empty/uninitialized value is skipped.
console.log([1, 2, , 4].reduce((a, b) => a + b)); // 7
console.log([1, 2, undefined, 4].reduce((a, b) => a + b)); // NaN
.map()method (and others like it) skip uninitialized array positions.Array(3).fill(null).map(x => 'a')