Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,100 --> 00:00:04,500
Now, the other crucial concept
2
00:00:04,500 --> 00:00:07,110
that's related to arrays and objects
3
00:00:07,110 --> 00:00:10,650
about which you should know is the special spread operator
4
00:00:10,650 --> 00:00:12,990
that exists in JavaScript.
5
00:00:12,990 --> 00:00:15,810
For that, let's for example, say that we wanna merge
6
00:00:15,810 --> 00:00:19,050
this hobbies list with another hobbies list.
7
00:00:19,050 --> 00:00:20,250
In this case, for example,
8
00:00:20,250 --> 00:00:22,623
another list that only contains one item.
9
00:00:23,700 --> 00:00:26,760
If I would want to create a merged list, I could do that
10
00:00:26,760 --> 00:00:30,120
by creating a new list with the square brackets.
11
00:00:30,120 --> 00:00:33,240
And then, I could use the special spread operator
12
00:00:33,240 --> 00:00:35,190
which looks like this.
13
00:00:35,190 --> 00:00:37,260
Three dots, yes, it looks weird,
14
00:00:37,260 --> 00:00:41,250
but this is JavaScript syntax using three dots,
15
00:00:41,250 --> 00:00:44,280
and then the name of the first array you wanna merge
16
00:00:44,280 --> 00:00:45,390
into this new array.
17
00:00:45,390 --> 00:00:47,430
For example, hobbies.
18
00:00:47,430 --> 00:00:50,760
These three dots will pull out
19
00:00:50,760 --> 00:00:52,830
all the elements of this array,
20
00:00:52,830 --> 00:00:56,070
so sports and cooking in this case, and add them
21
00:00:56,070 --> 00:01:00,393
as separate, comma separated values to this new list.
22
00:01:01,440 --> 00:01:05,400
If I would just add hobbies like this, and new hobbies
23
00:01:05,400 --> 00:01:08,970
like this, I would get a new array,
24
00:01:08,970 --> 00:01:10,380
which when output
25
00:01:10,380 --> 00:01:14,610
to the console, will actually look like this.
26
00:01:14,610 --> 00:01:18,603
Now, it's an array with two nested arrays inside.
27
00:01:19,740 --> 00:01:23,133
This might sometimes be what you want, but often, it's not.
28
00:01:24,360 --> 00:01:27,510
If I instead use the three dots
29
00:01:27,510 --> 00:01:32,400
in front of the arrays to use this spread operator,
30
00:01:32,400 --> 00:01:35,490
I will pull out the values from these arrays,
31
00:01:35,490 --> 00:01:38,703
and add them as standalone values to this array.
32
00:01:39,780 --> 00:01:43,470
And with that, if I reload this new array I get,
33
00:01:43,470 --> 00:01:45,870
now does not contain nested arrays,
34
00:01:45,870 --> 00:01:49,113
but instead, the values from the merged arrays.
35
00:01:50,070 --> 00:01:52,020
And that's what the spread operator does.
36
00:01:52,020 --> 00:01:56,340
It pulls out values from an array, and adds them
37
00:01:56,340 --> 00:02:01,200
as separate, comma separated values to a new array here.
38
00:02:01,200 --> 00:02:03,600
And we will indeed use this spread operator
39
00:02:03,600 --> 00:02:05,100
from time to time in this course.
40
00:02:05,100 --> 00:02:07,450
And therefore, you should also know about this.
41
00:02:08,639 --> 00:02:12,390
You can also not just use this spread operator on arrays,
42
00:02:12,390 --> 00:02:14,520
but also an objects.
43
00:02:14,520 --> 00:02:18,690
For example, if I have my extended user object here
44
00:02:18,690 --> 00:02:22,680
where I also have the isAdmin flag, let's say,
45
00:02:22,680 --> 00:02:27,060
a property named isAdmin, which stores a Boolean value.
46
00:02:27,060 --> 00:02:31,350
And I now wanna merge in the properties from the other user.
47
00:02:31,350 --> 00:02:33,900
Now, for that, I can again use the spread operator
48
00:02:33,900 --> 00:02:38,310
because it's also available in objects, and spread my user
49
00:02:38,310 --> 00:02:41,763
with help of these three dots into this extended user.
50
00:02:42,690 --> 00:02:45,870
Here, the spread operator will pull out
51
00:02:45,870 --> 00:02:49,860
all the key value pairs from this object,
52
00:02:49,860 --> 00:02:53,553
and add them as key value pairs to that object here.
53
00:02:54,480 --> 00:02:58,620
The offer, if I console.log this extendedUser now,
54
00:02:58,620 --> 00:03:03,270
I'll get a new user which has this isAdmin key,
55
00:03:03,270 --> 00:03:06,030
but which also has these key value pairs
56
00:03:06,030 --> 00:03:07,293
from this user here.
57
00:03:09,090 --> 00:03:12,663
All thanks to this spread operator, to the three dots.
4662
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.