July 2008
Beginner
356 pages
6h 8m
English
The Array constructor creates array objects:
>>> var a = new Array(1,2,3);
This is the same as the array literal:
>>> var a = [1,2,3]; //recommended
When you pass only one numeric value to the Array constructor, it's assumed to be the array length. An array with this length will be created, and filled with undefined elements.
>>> var a = new Array(3); >>> a.length
3
>>> a
[undefined, undefined, undefined]
This can sometimes lead to some unexpected behavior. For example, the following use of the array literal is valid:
>>> var a = [3.14] >>> a
[3.14]
However, passing the floating-point number to the Array constructor is an error:
>>> var a = new Array(3.14)
invalid array length
|
Property/Method |
Description |
|---|---|
|
|
Read now
Unlock full access