Tip 22 Create Arrays of a Similar Size with map()

In this tip, you’ll learn how to pull out a subset of information from an array using map().

In the previous tip, you saw how you could rewrite a simple for loop with an array method. Now you’re going to start exploring how to use specific array methods.

You’ll begin with map() (not to be confused with the Map object). It’s fairly common, and your new array receives the information you return in a brand new array. In other words, the return value is transparent, which isn’t the case with other array methods. Here’s another good reason to start with map(): the name “map” isn’t very expressive. What does that even mean? When I first learned it, I needed a fair amount of experience before I could ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.