Reading this article requires programming experience in other languages.
An array in JavaScript is an object (rather than a non-linear allocated memory).
To create an array through array literal:
Copy Code code as follows:
var empty = [];
var numbers = [
' Zero ', ' one ', ' two ', ' three ', ' four ',
' Five ', ' six ', ' seven ', ' eight ', ' nine '
];
EMPTY[1]//undefined
NUMBERS[1]//' one '
Empty.length//0
Numbers.length//10
The array has a property length (and the object does not) to represent the lengths of the array. The value of length is the maximum integer property name plus 1 for the array:
Copy Code code as follows:
var myarray = [];
Myarray.length; 0
MYARRAY[1000000] = true;
Myarray.length; 1000001
We can modify the length directly:
Length change will not cause more space to be allocated
Length is changed to small, all attributes with subscript greater than or equal to length are deleted
Because arrays are also objects, you can use Delete to remove elements from an array:
Copy Code code as follows:
Delete Number[2];
NUMBER[2] = = undefined;
This removes the element from the array leaving a void.
JavaScript provides an array of methods that are placed in Array.prototype (not described in detail here).