Here’s a list of commonly used array methods in JavaScript. Each method includes a simple explanation and an example.
Array Methods Reference Table
Method | What It Does | Example |
---|---|---|
concat() | Combines two or more arrays into one new array. |
|
every() | Returns true if all elements pass a test. |
|
filter() | Creates a new array with elements that pass a test. |
|
forEach() | Runs a function for each element in the array. |
|
indexOf() | Returns the index of the first match, or -1 if not found. |
|
join() | Joins all elements into a string with a separator. |
|
lastIndexOf() | Finds the last matching index of a value. |
|
map() | Creates a new array with the result of a function for each element. |
|
pop() | Removes the last item and returns it. |
|
push() | Adds an item to the end and returns new length. |
|
reduce() | Reduces the array to a single value. |
|
reduceRight() | Like reduce() , but from right to left. |
|
reverse() | Reverses the order of elements in the array. |
|
shift() | Removes the first item and returns it. |
|
slice() | Returns a piece of the array (does not change the original). |
|
some() | Returns true if any item passes the test. |
|
sort() | Sorts elements alphabetically by default. |
|
splice() | Adds/removes items from any index. |
|
toString() | Converts array to a comma-separated string. |
|
unshift() | Adds items to the start and returns new length. |
|