JavaScript Array Methods: ForEach, Filter, Map & Reduce

Jake Lira
2 min readJan 30, 2021

As I continue to grow as a software engineer, I am working to become more comfortable working through algorithms. I find it useful to have knowledge of multiple array methods “in my back pocket.” Here are a few methods that have helped me in the past, and a great place to get started.

forEach()

This built in array is similar to a for/of loop

The expected output would be:

filter()

The filter method returns a new array with all elements that have passed the given test. With the provided array of games, the filter method will return any games that have a title that has a length greater than 6.

The expected output would be:

map()

The map() method also creates a new array that is populated with the results. In this case, we are given an array of numbers and we are going to map through that array multiplying each element by 2.

expected output:

reduce()

The reduce method will build or add to its value by going through each element in an array and adding it to the current value. The difference with this method is that we need to provide our own reducer function for it to work properly.

Expected output: 66

Now there are various methods available to choose from depending on the situation. These are just a few that I found useful when first getting started. You can find more on the MDN Web Docs:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

--

--