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 ...
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.