From the course: JavaScript Essential Training
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using the map() array method - JavaScript Tutorial
From the course: JavaScript Essential Training
Using the map() array method
- [Instructor] The map method for arrays to serve special mention because it is heavily used when working with complex lists of data and when using frameworks like React. The map method takes an existing array, then does something to each of the items in the array and returns each of those items into a new array. In contrast, for each array method we looked at earlier loops through the array but doesn't create anything unless we explicitly tell it to and nothing is ever returned into something else. So if we need to create a new array with the items from an existing array and we want to change those items in the process, we use the map method. Looking at our foreach example from earlier, you see we use the foreach loop to loop through each of the items. Then we create a new element for each item, insert the item value into that element the "li" and then we append that item immediately to the stuff list ul so that it…
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.
Contents
-
-
-
-
-
-
-
-
-
-
The real-world function2m 49s
-
(Locked)
Functions and methods6m 23s
-
(Locked)
A standard function3m 53s
-
(Locked)
The arrow function4m 49s
-
(Locked)
Arrow functions and "this"4m 20s
-
(Locked)
Practice: Build a function1m 31s
-
(Locked)
Pass data to a function with parameters4m 56s
-
(Locked)
Return values from a function7m 1s
-
(Locked)
Practice: Pass values between functions2m 33s
-
(Locked)
Callbacks5m 29s
-
(Locked)
Conditional if...else statement5m 52s
-
(Locked)
Logical operators3m 31s
-
(Locked)
Conditional switch statement5m 55s
-
(Locked)
Looping through content5m 19s
-
(Locked)
Using the map() array method4m 52s
-
(Locked)
Challenge intro: Create a content factory2m 36s
-
(Locked)
Solution: Create a content factory5m 21s
-
-
-
-