Member-only story

How to use Map, Reduce, and Filter in JavaScript?

Here’s how to use the core array methods used in Functional Programming.

Afan Khan
5 min readSep 25, 2023

--

If you’re a non-premium user, click here to read this article for free. If not, continue reading.

Create an image of a person in the midst of a journey, sitting at a cozy cafe table with a map spread out before them. The person is intently studying the map, using their finger to trace various routes and destinations. Their bag or luggage is open beside them, and they are carefully selecting items to take on their adventure, placing some items neatly on the table and leaving others in the bag. The person has a thoughtful expression on their face, as they filter their choices on the map….
Made with Leonardo AI. The prompt is in the Alt Text.

Developers and beginners still seem confused about these three array methods irrespective of the articles on Medium, freeCodeCamp, or any other platform.

I decided to explain these methods once again in simple and precise language. I’m contributing and adding to the other great articles on this topic.

Let’s start with the map()method.

Map

First, the Map object, a key-pair-based data structure, is not the map()method. Both of them solve different problems. They are not related or the same. We address the former as an Object and the latter as a method (function).

The map method allows you to run a callback function on each element of an array without modifying the original array. It creates a new duplicate array and scans through each element like a standard loop.

It has three arguments. The first one represents a variable that will hold the current element of the repetition. The second one stores the index of the current element in the loop from the array. The third…

--

--

Afan Khan
Afan Khan

Written by Afan Khan

I create tools for innovators and problem solvers to bring forward new and impactful technological advancements.

No responses yet