JavaScript (ES2026) reference · 42 entries
JavaScript Array Methods
Every JavaScript array method, from at() to with(), with syntax, parameters and examples you can run. Shows which methods change the array and which return a copy.
Methods marked changes the array (push(), sort(), splice(), …) modify the original. Since ES2023 there
are copying versions too: toSorted(), toReversed(), toSpliced() and with().
| Name | Description | Since |
|---|---|---|
array.at() |
Return the element at an index, where negative indexes count from the end: arr.at(-1) is the last element. | ES2022 |
array.concat() |
Return a new array that joins this array with other arrays or values. The original arrays are not changed. | ES3 |
array.copyWithin() |
Copy a slice of the array to another position in the same array, overwriting what's there. Changes the array in place. | ES2015 |
array.entries() |
Return an iterator of [index, element] pairs, handy for looping with both the index and the value. | ES2015 |
array.every() |
Return true if every element passes a test function. Stops at the first failure; an empty array returns true. | ES5 |
array.fill() |
Fill all or part of an array with a static value, changing it in place. Often used to create an array of defaults. | ES2015 |
array.filter() |
Return a new array with only the elements that pass a test function. The original array is not changed. | ES5 |
array.find() |
Return the first element that passes a test function, or undefined if none does. | ES2015 |
array.findIndex() |
Return the index of the first element that passes a test function, or -1 if none does. | ES2015 |
array.findLast() |
Return the last element that passes a test function, searching from the end, or undefined if none does. | ES2023 |
array.findLastIndex() |
Return the index of the last element that passes a test function, or -1 if none does. | ES2023 |
array.flat() |
Return a new array with nested arrays flattened into it, one level deep by default or to a given depth. | ES2019 |
array.flatMap() |
Map each element with a function, then flatten the result one level. Useful when one element becomes several. | ES2019 |
array.forEach() |
Call a function once for each element. It returns undefined, so use map() when you need a new array. | ES5 |
array.includes() |
Return true if the array contains a value, using SameValueZero equality (so it finds NaN, unlike indexOf). | ES2016 |
array.indexOf() |
Return the first index at which a value is found (using ===), or -1 if it isn't in the array. | ES5 |
array.join() |
Join all elements into one string, separated by commas or by a separator you choose. | ES1 |
array.keys() |
Return an iterator of the array's indexes, including indexes of empty slots. | ES2015 |
array.lastIndexOf() |
Return the last index at which a value is found (using ===), searching backwards, or -1 if it isn't there. | ES5 |
array.length |
The number of elements in the array. Setting it shortens or extends the array. | ES1 |
array.map() |
Return a new array with the results of calling a function on every element. The original array is unchanged. | ES5 |
array.pop() |
Remove the last element from the array and return it. Changes the array; returns undefined if it is empty. | ES3 |
array.push() |
Add one or more elements to the end of the array and return the new length. Changes the array in place. | ES3 |
array.reduce() |
Reduce the array to a single value by running a reducer function on each element, carrying an accumulator along. | ES5 |
array.reduceRight() |
Like reduce(), but processes the array from the last element to the first. | ES5 |
array.reverse() |
Reverse the array in place and return it. Use toReversed() to get a reversed copy instead. | ES1 |
array.shift() |
Remove the first element of the array and return it, moving the other elements down. Returns undefined if empty. | ES3 |
array.slice() |
Return a shallow copy of part of the array, from start up to (not including) end. The original is not changed. | ES3 |
array.some() |
Return true if at least one element passes a test function. Stops at the first match; an empty array returns false. | ES5 |
array.sort() |
Sort the array in place and return it. Without a compare function elements are sorted as strings, so numbers need one. | ES1 |
array.splice() |
Remove, replace or insert elements at a position, changing the array in place. Returns the removed elements. | ES3 |
array.toReversed() |
Return a new array with the elements in reverse order, leaving the original unchanged. | ES2023 |
array.toSorted() |
Return a new sorted array, leaving the original unchanged. Takes the same compare function as sort(). | ES2023 |
array.toSpliced() |
Return a new array with elements removed, replaced or inserted at a position, leaving the original unchanged. | ES2023 |
array.toString() |
Return a string of the array's elements separated by commas. Called automatically when an array is used as text. | ES1 |
array.unshift() |
Add one or more elements to the start of the array and return the new length. Changes the array in place. | ES3 |
array.values() |
Return an iterator of the array's values, the same thing a for…of loop uses. | ES2015 |
array.with() |
Return a copy of the array with one element replaced, leaving the original unchanged. Negative indexes count from the end. | ES2023 |
Array.from() |
Create a new array from an iterable or array-like object, with an optional function to map each element. | ES2015 |
Array.fromAsync() |
Create an array from an async iterable or iterable of promises, awaiting each element. Returns a promise. | ES2026 |
Array.isArray() |
Return true if a value is an array. More reliable than typeof, which reports 'object' for arrays. | ES5 |
Array.of() |
Create a new array from its arguments. Unlike Array(3), Array.of(3) makes [3], not an empty array of length 3. | ES2015 |