Skip to content

The JavaScript map() Function

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'
→ Download my free JavaScript Handbook!

THE VALLEY OF CODE

THE WEB DEVELOPER's MANUAL

You might be interested in those things I do:

  • Learn to code in THE VALLEY OF CODE, your your web development manual
  • Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
  • I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
  • Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
  • Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
  • Find me on X

Related posts that talk about js: