An array class for storing lists of objects or data.
// creating a simple array
var arr = new Array;
arr[0] = "aaa";
arr[1] = "bbb";
arr[2] = "ccc";
for (var i in arr)
{
alert("element " + i +" is " + arr[i]);
}
// sort an array of strings
var array_of_strings = new Array("Finch",
"Bluebird",
"Goose",
"Sparrow",
"Hummingbird",
"Duck");
array_of_strings.sort();
alert(array_of_strings);
// sort an array of numbers -- this requires
// writing a sort routine of our own, because
// by default the sort() method sorts as if
// all elements were strings
function numericSort(a, b)
{
return (a < b ? -1 : 1);
}
var array_of_numbers = new Array(5,4,10,50,45,52,1,12);
array_of_numbers.sort(numericSort);
alert(array_of_numbers);
Returns a new Array, created by concatenating the input elements to the array.
Returns a new array, without modifying the original array, formed by concatenating the input elements with the elements of the array.
Returns a string formed by converting all elements of array to strings and concatenating them with the separator added between elements. If a separator is not supplied, a "," is used.
Joins the elements of the array into a string, where the individual elements of the array are separated by separator if it is specified, or by "," if the separator is not specified.
Returns the last element of the array if the array is not empty, otherwise returns undefined.
Deletes and returns the last element of the array. If the array is empty, the function returns undefined and leaves the array unchanged.
The new length of the array.
Appends a number of elements to the end of an Array.
Reverses the order of the elements of the array.
Returns the first element of the array.
Deletes and returns the first element of the array and moves all the other elements down one place. If the array is empty, the function returns undefined and does not modify the array.
A new array containing all elements of the array from start to end, including the start element, but excluding the end element.
Returns a new array containing all elements of array with an index greater or equal than start and less than end in order. If start or end is negative, the result of adding this negative number to the length of the array is used. If end is not specified, all elements from the start to the end of the array are used. Note: slice() does not modify array.
Returns the original array with the elements sorted.
Sorts the array and returns it using the compare_function function. If compare_function is not specified, the elements are converted to Strings and sorted according to the character encoding. Undefined elements will appear at the end of the array.
A new array containing the elements deleted from the array.
Deletes and returns the length elements of the array after start, including the element at start. If length is not supplied, all elements after start will be deleted. If newElem_1, ..., newElem_k are supplied, they will be inserted at start after the deletion.
Returns a localized string that represents the array.
Calls the function toLocaleString() on every element of the array and returns the results concatenated with a locale-specific separator.
Returns a string that represents the array.
Converts each element of the array to a string, concatenates the elements using the "," as a separator, and returns a single concatenated string of the elements.
Returns the new length of the array.
Inserts newElem_1, ..., newElem_k at the beginning of array, shifts other elements forward accordingly, and returns the new length of the array.