Skip to main content

Command Palette

Search for a command to run...

JavaScript Array Methods You Must Know

Updated
•3 min read•View as Markdown

In earlier discussions, we covered the fundamentals of arrays in JavaScript — creating arrays, accessing elements, modifying values, and iterating through them using loops. Those basics are important because arrays are one of the most commonly used data structures in JavaScript.

However, in real-world JavaScript development, developers often use built-in array methods instead of writing manual loops for many operations. These methods simplify tasks such as adding or removing elements, transforming data, filtering values, and combining results. They also make the code cleaner and easier to understand.

In this article, we’ll look at several important array methods including push(), pop(), map(), filter(), and reduce(). Understanding how these methods work will help you write more efficient and readable JavaScript code.


  1. Push() and pop()

Adds a new element to the end of an array or removes the last element from it, returning the updated array length when adding and the removed element when deleting.

output :

  1. shift() and unshift()

Removes the first element from an array and returns it (or undefined if the array is empty), or inserts new elements at the beginning of the array and returns the new length.

output :

  1. map()

The map() method runs a function on every element of an array and returns a new array containing the transformed results, without changing the original array.

output:

  1. filter()

The filter() method checks each element of an array using a callback function and returns a new array containing only the elements that satisfy the specified condition.

output :

  1. reduce()

The reduce() method processes each element of an array and reduces it to a single value (such as a sum, total, or combined result) using a callback function.

output :

50

Before array
[5, 10, 15, 20]

After reduce
50

6. forEach()

The forEach() method runs a function once for each element in an array, usually to perform an action like printing values, updating something, or running logic. It does not return a new array.

output :

1 2 3 4

Before array
[1, 2, 3, 4]

After forEach()
Array remains the same → [1, 2, 3, 4]


quick summary

push()
Adds one or more elements to the end of an array and returns the new array length.

pop()
Removes the last element from an array and returns the removed element.

shift()
Removes the first element from an array and returns the removed element.

unshift()
Adds one or more elements to the beginning of an array and returns the new array length.

map()
Runs a function on every element of an array and returns a new array with the transformed values.

filter()
Checks each element using a condition and returns a new array containing only the elements that satisfy the condition.

reduce()
Processes all elements of an array and reduces them to a single value (such as a total or combined result).

forEach()
Executes a function for each element in the array, usually for performing actions, but does not return a new array.