Master JavaScript Array methods in 5 Minutes

Here is a comprehensive list of JavaScript array methods, categorized for clarity:


Mutating Methods

These methods modify the original array.

  1. push() - Adds one or more elements to the end of the array.

  2. pop() - Removes the last element from the array.

  3. unshift() - Adds one or more elements to the beginning of the array.

  4. shift() - Removes the first element from the array.

  5. splice() - Adds, removes, or replaces elements at specific indices.

  6. sort() - Sorts the elements of the array in place.

  7. reverse() - Reverses the elements of the array.

  8. fill() - Fills all or part of the array with a static value.

  9. 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.

  1. concat() - Combines two or more arrays.

  2. slice() - Returns a shallow copy of a portion of an array.

  3. includes() - Checks if the array contains a certain value.

  4. indexOf() - Returns the first index of a specified value.

  5. lastIndexOf() - Returns the last index of a specified value.

  6. join() - Joins all elements into a string.

  7. toString() - Converts the array into a string.

  8. flat() - Flattens nested arrays into a single array.

  9. flatMap() - Maps each element and then flattens the result.


Iteration Methods

These methods iterate through the array and often accept a callback function.

  1. forEach() - Executes a callback for each element.

  2. map() - Creates a new array by applying a callback to each element.

  3. filter() - Creates a new array with elements that pass a test.

  4. reduce() - Applies a reducer function and returns a single value.

  5. reduceRight() - Similar to reduce(), but processes elements from right to left.

  6. find() - Returns the first element that satisfies a condition.

  7. findIndex() - Returns the index of the first element that satisfies a condition.

  8. some() - Checks if at least one element satisfies a condition.

  9. every() - Checks if all elements satisfy a condition.


Other Utility Methods

  1. Array.isArray() - Checks if a value is an array (static method).

  2. from() - Creates an array from an iterable or array-like object (static method).

  3. of() - Creates an array from a set of arguments (static method).

  4. keys() - Returns an iterator for array keys.

  5. values() - Returns an iterator for array values.

  6. entries() - Returns an iterator with key-value pairs for each index.

  7. toLocaleString() - Converts elements to a locale-specific string.


Newer Methods (ES6+ Updates)

  1. Array.prototype[@@iterator] - Returns the default iterator function for arrays (used in for...of loops).

  2. findLast() - Returns the last element that satisfies a condition (ES2023).

  3. findLastIndex() - Returns the index of the last element that satisfies a condition (ES2023).

  4. groupBy() (Proposal) - Groups array elements by a criterion.

  5. groupByToMap() (Proposal) - Groups elements into a Map.

ย