5 Min JavaScript Array methods
Here is a comprehensive list of JavaScript array methods, categorized for clarity:
Mutating Methods
These methods modify the original array.
push()
- Adds one or more elements to the end of the array.pop()
- Removes the last element from the array.unshift()
- Adds one or more elements to the beginning of the array.shift()
- Removes the first element from the array.splice()
- Adds, removes, or replaces elements at specific indices.sort()
- Sorts the elements of the array in place.reverse()
- Reverses the elements of the array.fill()
- Fills all or part of the array with a static value.copyWithin()
- Copies part of the array to another location in the same array.
Non-Mutating Methods
These methods return a new array or value without altering the original array.
concat()
- Combines two or more arrays.slice()
- Returns a shallow copy of a portion of an array.includes()
- Checks if the array contains a certain value.indexOf()
- Returns the first index of a specified value.lastIndexOf()
- Returns the last index of a specified value.join()
- Joins all elements into a string.toString()
- Converts the array into a string.flat()
- Flattens nested arrays into a single array.flatMap()
- Maps each element and then flattens the result.
Iteration Methods
These methods iterate through the array and often accept a callback function.
forEach()
- Executes a callback for each element.map()
- Creates a new array by applying a callback to each element.filter()
- Creates a new array with elements that pass a test.reduce()
- Applies a reducer function and returns a single value.reduceRight()
- Similar toreduce()
, but processes elements from right to left.find()
- Returns the first element that satisfies a condition.findIndex()
- Returns the index of the first element that satisfies a condition.some()
- Checks if at least one element satisfies a condition.every()
- Checks if all elements satisfy a condition.
Other Utility Methods
Array.isArray()
- Checks if a value is an array (static method).from()
- Creates an array from an iterable or array-like object (static method).of()
- Creates an array from a set of arguments (static method).keys()
- Returns an iterator for array keys.values()
- Returns an iterator for array values.entries()
- Returns an iterator with key-value pairs for each index.toLocaleString()
- Converts elements to a locale-specific string.
Newer Methods (ES6+ Updates)
Array.prototype[@@iterator]
- Returns the default iterator function for arrays (used infor...of
loops).findLast()
- Returns the last element that satisfies a condition (ES2023).findLastIndex()
- Returns the index of the last element that satisfies a condition (ES2023).groupBy()
(Proposal) - Groups array elements by a criterion.groupByToMap()
(Proposal) - Groups elements into a Map.