JavaScript Array
Object
Array Object
The Array object is used to store multiple values in a single variable:
var cars = ["Saab", "Volvo", "BMW"];
The index of the first array element is 0, the second is 1, and so on.
For more information about JavaScript Array, please refer to the JavaScript Array Object Manual.
Array Properties
Property | Description |
---|---|
constructor | Returns the prototype function that creates the array object. |
length | Sets or returns the number of elements in an array. |
prototype | Allows you to add properties or methods to the array object. |
Array Object Methods
Method | Description |
---|---|
concat() | Joins two or more arrays and returns the result. |
copyWithin() | Copies elements within the array to another position in the array. |
entries() | Returns an iterable object of the array. |
every() | Checks if every element in the array passes the test. |
fill() | Fills the array with a static value. |
filter() | Creates a new array with every element in the array that passes the test. |
find() | Returns the value of the first element in the array that satisfies the provided testing function. |
findIndex() | Returns the index of the first element in the array that satisfies the provided testing function. |
forEach() | Executes a provided function once for each array element. |
from() | Creates an array from an object. |
includes() | Determines whether an array includes a certain value. |
indexOf() | Searches the array for an element and returns its position. |
isArray() | Checks if an object is an array. |
join() | Joins all elements of an array into a string. |
keys() | Returns an iterable object containing the keys of the array. |
lastIndexOf() | Searches the array for an element and returns its last position. |
map() | Creates a new array with the results of calling a function for every array element. |
pop() | Removes the last element from an array and returns that element. |
push() | Adds one or more elements to the end of an array and returns the new length of the array. |
reduce() | Reduces the array to a single value (from left to right). |
reduceRight() | Reduces the array to a single value (from right to left). |
reverse() | Reverses the order of the elements in an array. |
shift() | Removes the first element from an array and returns that element. |
slice() | Selects a part of an array and returns a new array. |
some() | Checks if any of the elements in an array pass the test. |
sort() | Sorts the elements of an array. |
splice() | Adds or removes elements from an array. |
toString() | Converts an array to a string and returns the result. |
unshift() | Adds one or more elements to the beginning of an array and returns the new length. |
valueOf() | Returns the primitive value of the array object. |