Skip to content

The JavaScript map() Function

New Course Coming Soon:

Get Really Good at Git

The details of the `map()` Function in JavaScript

map() is key method of an array when it comes to thinking in functional programming terms.

This example iterates a and builds a new array with the result of executing f() on each a element:

const b = a.map(f)

Given an array, we can use map() to create a new array from the initial one, and then filtering the result using filter(). This short example creates a new array to get the first letter of each item in the list array, and filters the one that matches A:

const list = ['Apple', 'Orange', 'Egg']
list.map(item => item[0]).filter(item => item === 'A') //'A'
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Get my JavaScript Beginner's Handbook
→ Read my JavaScript Tutorials on The Valley of Code
→ Read my TypeScript Tutorial on The Valley of Code

Here is how can I help you: