Working with Arrays, Variables, and Naming Practices - How Do You Get the Length for an Array, and How Can You Create an Empty Array of Fixed Length?

Tell us what’s happening:

let arr = new Array(3);
console.log(arr);
right answer is [undefined,undefined,undefined]

not [<3 empty items>]
please check

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0

Challenge Information:

Working with Arrays, Variables, and Naming Practices - How Do You Get the Length for an Array, and How Can You Create an Empty Array of Fixed Length?

1 Like

the result is a sparse array, see the text below the example with a similar code

the interactive editor we use shows the sparse array with undefined, while if you try in an other environment like the browser console you would see a different visualization, like [<3 empty items>], or even [,,,]

this has made the lesson a bit confusing, it is being reworked