Welcome to the Treehouse Community
Looking to learn something new?
one number in new Array(50) is only = array.length
I understand that the array constructor is not recommended, but I find it interesting that when I pass just one number into the parameter of an array constructor, that number is seen as the length of the array. However when I have 2 elements in my array constructor, it is seen as an array of length 2.
In the code below, I have 50 in the parameter of the array constructor, but what if I want 50 to be a value , and not the length of the array constructor, is it possible with array constructors, or is my only choice an array literal. Cheers!
var show = new Array( 50); alert(show.length); </script>
Adam Moore21,956 Points
I believe the way it works is that a single value in the constructor is interpreted as the length of the array, with multiple values each being a value within the array, just like you said. However, to use:
<script> var show = ; alert(show.length); </script>
is really not that bad to have to write. :)