An array class for storing lists of objects or data.
// creating a simple array
const arr = ["aaa", "bbb", "ccc"];
for (let i = 0; i < arr.length; ++i) {
alert(`element ${i} is ${arr[i]}`);
}
// sort an array of strings
const birds = ["Finch",
"Bluebird",
"Goose",
"Sparrow",
"Hummingbird",
"Duck"];
birds.sort();
alert(birds);
// sort an array of numbers -- this requires a comparison function
// of our own, because by default the sort() method sorts as if all
// elements were strings
const numbers = [5, 4, 10, 50, 45, 52, 1, 12];
numbers.sort((a, b) => a - b);
alert(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.
True if every callback returned a truthy value, else false.
Invokes callback with (element, index, array) for each assigned element until the callback returns a falsy value.
A new array of the elements that passed the test.
Invokes callback with (element, index, array) for each assigned element and collects the elements for which the callback returns a truthy value.
The first element that passed the test, or undefined.
Invokes callback with (element, index, array) for every index (unassigned indexes are passed as undefined) until the callback returns a truthy value.
The first matching index, or -1.
Like find, but returns the matching index instead of the element.
Invokes callback with (element, index, array) for each assigned element, front to back. this_arg, if supplied, is bound as 'this' inside the callback.
True if the element is found, false otherwise.
Like indexOf, but returns a boolean and treats NaN as equal to NaN.
The first matching index, or -1 if the element is not found.
Searches the array front to back for search_element using strict equality (===), starting at from_index (default 0; a negative value counts back from the end).
True if the value is an Array, false otherwise.
Returns true if value is an Array object.
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.
The last matching index, or -1 if the element is not found.
Searches the array back to front for search_element using strict equality (===), starting at from_index (default: the last element; a negative value counts back from the end).
A new array of the callback's return values.
Invokes callback with (element, index, array) for each assigned element and collects the return values into a new array at the same indexes.
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.
The final accumulator value.
Invokes callback with (accumulator, element, index, array) for each assigned element, front to back. Without initial_value, the first element seeds the accumulator; on an empty array that is a runtime error.
The final accumulator value.
Like reduce, but iterates from the last element to the first.
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.
True if any callback returned a truthy value, else false.
Invokes callback with (element, index, array) for each assigned element until the callback returns a truthy value.
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.