1
00:00:00,680 --> 00:00:06,050
There's one last method that we're going to be covering in JavaScript, and that's the map method,

2
00:00:06,050 --> 00:00:12,620
and it kind of ties everything together where we can reconstruct a brand new array using contents from

3
00:00:12,620 --> 00:00:18,590
existing data so we can create a brand new array by calling a function and looping through each one

4
00:00:18,590 --> 00:00:19,260
of the elements.

5
00:00:19,730 --> 00:00:25,060
So, of course, there is a challenge for this lesson, and this is to use maps.

6
00:00:25,070 --> 00:00:30,710
So this map is going to work similar to what we've seen earlier where we can reconstruct the array.

7
00:00:30,920 --> 00:00:34,400
So we've got an array num array, all numbers in there.

8
00:00:36,000 --> 00:00:40,500
And we're going to use that existing array and rebuild it.

9
00:00:41,840 --> 00:00:48,230
Multiplying each one of the values by 50 and then returning it back into my party and I would lock out

10
00:00:48,230 --> 00:00:50,910
the values of my operate into the console.

11
00:00:51,230 --> 00:00:52,400
So go ahead and try this out.

12
00:00:52,400 --> 00:00:55,420
You can pause the video and I'll walk you through it coming up.

13
00:00:55,980 --> 00:00:58,950
So first thing that we need to do is construct our array.

14
00:00:59,120 --> 00:01:03,260
So this is just going to be a no arrests are going to have a bunch of numbers in here.

15
00:01:03,410 --> 00:01:08,090
Just come a separate them and they can just be any number we want.

16
00:01:08,090 --> 00:01:12,600
Or we could use the existing array that we have within the sample.

17
00:01:13,460 --> 00:01:20,840
So once we've created our array, save that and you can double check just to make sure you've got your

18
00:01:20,840 --> 00:01:21,440
array there.

19
00:01:21,920 --> 00:01:24,040
And we're going to build a brand new array.

20
00:01:24,050 --> 00:01:28,790
So we're taking our map and we're going to use the number array.

21
00:01:28,810 --> 00:01:36,560
So that existing array that we have and using the map method, we've got function for X at first of

22
00:01:36,560 --> 00:01:41,390
all, console log out the value of X so you can see it within the console.

23
00:01:41,600 --> 00:01:43,090
It's going to run the block a code.

24
00:01:43,400 --> 00:01:50,900
So what it's doing is it's going through each one of the items in the array and holding the value of

25
00:01:50,900 --> 00:01:54,770
that item as X. So we can do something with it.

26
00:01:55,050 --> 00:02:02,050
And just as we saw before, whatever we're returning back is going to be part of the new map array.

27
00:02:02,270 --> 00:02:08,990
So we're constructing this brand new map array and we're checking to see we're taking X and we're multiplying

28
00:02:08,990 --> 00:02:10,110
it by 50.

29
00:02:10,790 --> 00:02:16,460
So now when we get our brand new constructed array, all of the values we've used, all of the values

30
00:02:16,460 --> 00:02:19,860
in the current number array, and we've simply multiplied them by 50.

31
00:02:20,300 --> 00:02:25,570
So this is a really useful function as you've got a lot of data within an array.

32
00:02:25,670 --> 00:02:31,250
And if you want to do something with that data, you can use a map in order to run blocks of code and

33
00:02:31,250 --> 00:02:33,980
then reconstruct brand new arrays from that data.
