Array Object (JavaScript)
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Provides support for creation of arrays of any data type.
arrayObj = new Array()arrayObj = new Array([size])arrayObj = new Array([element0[, element1[, ...[, elementN]]]])
After an array is created, you can access the individual elements of the array by using [ ] notation, for example:
var my_array = new Array(); for (i = 0; i < 10; i++) { my_array[i] = i; } x = my_array[4];
Since arrays in JavaScript are zero-based, the last statement in the preceding example accesses the fifth element of the array. That element contains the value 4.
If only one argument is passed to the Array constructor, and the argument is a number, it must be an unsigned 32-bit integer (< approximately four billion). That value then becomes the size of the array. If the value is a number, but is less than zero or is not an integer, a run-time error occurs.
If a single value is passed to the Array constructor, and it is not a number, the length property is set to 1, and the value of the only element becomes the single, passed-in argument.
Notice that JavaScript arrays are sparse arrays, that is, although you can allocate an array with many elements, only the elements that actually contain data exist. This reduces the amount of memory used by the array.
The Array object was introduced in
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Also supported in Metro style apps. See Version Information.
. Some members in the following lists were introduced in later versions.The following table lists the methods of the Array object.
|
Method |
Description |
|---|---|
|
Returns a new array consisting of a combination of two arrays. |
|
|
Checks whether a defined callback function returns true for all elements in an array. |
|
|
Calls a defined callback function on each element of an array, and returns an array of values for which the callback function returns true. |
|
|
Calls a defined callback function for each element in an array. |
|
|
Returns a Boolean value that indicates whether an object has a property with the specified name. |
|
|
Returns the index of the first occurrence of a value in an array. |
|
|
Returns a Boolean value that indicates whether an object exists in another object's prototype chain. |
|
|
Returns a String object consisting of all the elements of an array concatenated together. |
|
|
Returns the index of the last occurrence of a specified value in an array. |
|
|
Calls a defined callback function on each element of an array, and returns an array that contains the results. |
|
|
Removes the last element from an array and returns it. |
|
|
Returns a Boolean value that indicates whether a specified property is part of an object and whether it is enumerable. |
|
|
Appends new elements to an array, and returns the new length of the array. |
|
|
Accumulates a single result by calling a defined callback function for all elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
|
|
Accumulates a single result by calling a defined callback function for all elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
|
|
Returns an Array object with the elements reversed. |
|
|
Removes the first element from an array and returns it. |
|
|
Returns a section of an array. |
|
|
Checks whether a defined callback function returns true for any element of an array. |
|
|
Returns an Array object with the elements sorted. |
|
|
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. |
|
|
Returns a string using the current locale. |
|
|
Returns a string representation of an object. |
|
|
Inserts new elements at the start of an array. |
|
|
Returns the primitive value of the specified object. |