15.4.2.2 new Array(len)

2010-07-04

array new Array(len:uint|mixed) throws RangeError

This is a special case of the constructor that only applies when exactly one argument is passed on to the Array constructor.

If this argument is a number and a uint, length is set to it and the array will otherwise remain empty (and therefore not sparse).
If this argument is a number but not a uint, a RangeError is thrown.

If the argument is not a number, length is set to 1 and the argument is inserted into the array, getting [[Writable]]:true, [[Configurable]]:true, [[Enumerable]]:true.

So take care when trying to initialize the array through the constructor with one number parameter. It will fail.

Also, to create a new array you should use []. This method does not have that limitation (so [5] will create an array with one element in it; 5) and is optimized in most engines. It's an accepted best practice.