new Array (), does not require any parameters.
things is an array, and you assign values to both
things  and
things , space for elements 23 and 200 will surely be allocated, but space for elements 24 through 199 may not be. Even so, the expression "
things . length" will return 201, because the last defined element in the array is element #200. This does not mean, however, that storage for 201 elements has actually been allocated.
Did you know that array indeces can be values other than positive integers? In fact, when it comes to indexing arrays, you can use just about anything! For example, the expressions "
things [document . window]" and "
window ["location"], and you will see that it is exactly the same as
window . location! Here's an even weirder one: Try the statement,
window ["alert"] ("Wow!") and you will see that this is equivalent to
window . alert ("Wow!")!
Pretty trippy, isn't it?
Now, as I inferred earlier, the expression "
array_name . length" does not return the number of elements stored in the array. Instead, it returns one of the following two values, whichever is greater:
newstatement that created it. This is 0 if the constructor was called without parameters (i.e.,
new Array ()).
These rules have exceptions, because there are certain positive integers which are not considered normal array indeces. Consider the following program:
a = new Array (); a [0x3ffffffe] = 0; document . write ("<p>a . length = " + a . length + "</p>"); b = new Array (); b [0x3fffffff] = 0; document . write ("<p>b . length = " + b . length + "</p>"); c = new Array (); c [0x40000000] = 0; document . write ("<p>c . length = " + c . length + "</p>"); d = new Array (); d [0x40000001] = 0; document . write ("<p>d . length = " + d . length + "</p>");
On my system (Windows 95, Netscape 4), this produces the following output (the results may be different on your system):
a . length = 1073741823
b . length = undefined
c . length = 0
d . length = 0
Note how the expression
array_name . length freaks out when indeces higher than 0x3ffffffe (1073741822) are used. I guess this means that if you wish to restrict your array indeces to normal, positive integers, then the largest integer you can use is 0x3ffffffe (1073741822).
However, if you don't care about the array's
length property working correctly, then any index is valid -- strings, objects, negative numbers, the works -- and the capacity of the array is limited only by the capacity of the user's machine.
30 August 1997