From the course: Learning Functional Programming with JavaScript (ES5)
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Mapping - JavaScript Tutorial
From the course: Learning Functional Programming with JavaScript (ES5)
Mapping
- [Instructor] The first of these functions we'll be talking about is called map. Map is used when you want to take all the elements in an array and convert them to some other value. For example, if you wanted to double all the elements in an array or convert an array of inch measurements into an array of centimeter measurements. The way we do this is by passing map an array and some function to apply to each element in the array. Map then returns another array that contains the return values of the function for each element. So in other words, it takes each element and maps it to the return value of the function we give it. If the function we pass is something like square, for example, map returns an array where each of the numbers has been squared. And of course, you can pass in an anonymous function to make it do essentially whatever you want. There is one important thing to remember with the map function and the rest of these functions. In typical functional fashion, they don't…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.