Map, Filter, Reduce: The Holy Trinity of Array Methods

Travis Waith-Mair
Non-Traditional Dev
5 min readMay 10, 2019

--

Photo by Alexander Watts on Unsplash

I have learned a few programming languages over the years and there are many common things that most languages have. Two things that are almost universal in all of them are Arrays and for…loops. For…loops and Arrays go hand in hand in most languages, so much so that they are often taught together, or at least close together. It’s just how you typically iterate over an array.

So when I learned JavaScript and needed to iterate over an array, you can guess what tool I typically used. Sure I would use some of the variations of the For…loop, such as the For…in and then the For…of when I started learning ES6 syntax, but they were all based on the same pattern of a For…loop, just with syntactic sugar on it.

Then I started to learn React and I learned about this method built into arrays called map and my world was opened up. I learned that For…loops were not the only ways to iterate over an array. As I started to learn about map I found out that it wasn’t the only method available to iterate over an array. Around this time, a mentor of mine made the claim to me, “In Javascript, if you are using a For…loop with an array, then you are probably doing something wrong.”

I have since come to the same conclusion, the methods built into Javascript arrays are extremely useful. Since learning them, I can’t remember the…

--

--