Array
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
Members of the Array Objects
|
Property/Method |
Description |
|---|---|
|
|
The number of elements in the array. >>> [1,2,3,4].length 4 |
|
|
Merges arrays together. >>> [1... |