Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,180 --> 00:00:07,030
In the last lecture we had a look at reference of primitive types something super important to keep
2
00:00:07,030 --> 00:00:09,800
in mind when working with javascript.
3
00:00:10,030 --> 00:00:14,260
Another thing you will see quite a lot in this course are array functions.
4
00:00:14,260 --> 00:00:17,240
We already saw filter a couple of lectures ago.
5
00:00:17,350 --> 00:00:20,550
We also got sort, map and so on.
6
00:00:20,860 --> 00:00:22,670
Let me quickly show you what I mean.
7
00:00:22,810 --> 00:00:27,560
The good old numbers array with 1, 2 and 3.
8
00:00:27,970 --> 00:00:34,510
Now let's say we want to turn this into an array where each number is doubled.
9
00:00:34,540 --> 00:00:41,370
So we have to doubleNumArray, something like that we can use an array function for this.
10
00:00:41,440 --> 00:00:45,050
We can take the numbers array and call map.
11
00:00:45,130 --> 00:00:47,150
Map is a built-in array method.
12
00:00:47,170 --> 00:00:49,070
And there are many of these methods.
13
00:00:49,420 --> 00:00:51,610
I will use quite a lot of them and they're not.
14
00:00:51,610 --> 00:00:57,940
Next generation javascript all these methods work in the same way though they take a function as an
15
00:00:57,940 --> 00:01:04,750
input and this function which is an arrow function here but could be a normal function is then simply
16
00:01:04,819 --> 00:01:09,050
executed on each element in the array here.
17
00:01:09,070 --> 00:01:13,830
So on each element in the numbers array, on 1 and 2 and 3.
18
00:01:14,260 --> 00:01:18,200
So therefore what we get in this arrow function is a number in the end.
19
00:01:18,220 --> 00:01:22,260
But you can name this argument whatever you want here.
20
00:01:22,260 --> 00:01:24,400
We can then simply return something.
21
00:01:24,610 --> 00:01:30,660
And what you have to do in this internal function depends on which area of function you are using.
22
00:01:30,670 --> 00:01:37,010
Check the docs in places like d Mozilla Developer Network docs to learn more about the available array
23
00:01:37,100 --> 00:01:38,470
functions.
24
00:01:38,470 --> 00:01:44,770
So in the map function we have to return the new value we want to turn the old one into so we could
25
00:01:44,770 --> 00:01:49,440
return num * 2 and since this is executed on every element here.
26
00:01:49,450 --> 00:01:55,890
It will return 2, 4 and 6 and conveniently map all the returns a new array.
27
00:01:55,900 --> 00:02:00,720
So a real new array which is then stored in doubleNumArray.
28
00:02:01,060 --> 00:02:12,520
So now if I output numbers and thereafter doubleNumArray like this and then I'll hit run you'll see
29
00:02:12,580 --> 00:02:19,750
the old one is unchanged but the new one holds double the values and I will explain what these functions
30
00:02:19,750 --> 00:02:21,620
do when we use them in the course.
31
00:02:21,850 --> 00:02:24,590
I just want to bring them to your attention right now.
32
00:02:24,670 --> 00:02:30,730
Explain that they always have this function which gets executed on each element and that they are not
33
00:02:30,760 --> 00:02:36,190
next generation javascript but normal javascript actually, be prepared to meet them.
34
00:02:36,190 --> 00:02:41,600
I will explain what they do when we see them and always feel free to dive into docs like the Mozilla
35
00:02:41,600 --> 00:02:43,840
developer network to learn more about them.
3635
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.