From the course: Learning Functional Programming with JavaScript (ES5)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Mapping

Mapping - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript (ES5)

Start my 1-month free trial

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…

Contents