1
00:00:00,000 --> 00:00:03,414
Hello everybody, Paul Sheriff here with

2
00:00:03,414 --> 00:00:07,470
Pluralsight. This module is Using the

3
00:00:07,470 --> 00:00:10,004
Powerful Spread Operator. What we're going

4
00:00:10,004 --> 00:00:11,823
to do in this particular module is

5
00:00:11,823 --> 00:00:15,121
demonstrate the power of spread. We'll use

6
00:00:15,121 --> 00:00:17,846
it to copy and concatenate arrays, we'll

7
00:00:17,846 --> 00:00:20,899
pass parameters to constructors, we'll

8
00:00:20,899 --> 00:00:24,704
perform shallow copy on objects, and we'll

9
00:00:24,704 --> 00:00:27,619
call functions with multiple parameters

10
00:00:27,619 --> 00:00:32,768
all using spread. Let's get started. The

11
00:00:32,768 --> 00:00:34,944
spread operator expands any iterable

12
00:00:34,944 --> 00:00:38,049
object such as a string or an array into

13
00:00:38,049 --> 00:00:41,192
another array. It also can be used for

14
00:00:41,192 --> 00:00:44,564
passing multiple arguments to a method.

15
00:00:44,564 --> 00:00:47,712
The syntax for spread uses the ellipsis

16
00:00:47,712 --> 00:00:51,439
symbol, or three dots, it's always on the

17
00:00:51,439 --> 00:00:55,172
right-hand side of an equal sign, and I

18
00:00:55,172 --> 00:00:58,041
want you to note, currently IE and Edge do

19
00:00:58,041 --> 00:01:01,230
not support the spread operator. Let's

20
00:01:01,230 --> 00:01:04,050
take a look at our first example of using

21
00:01:04,050 --> 00:01:09,047
spread by converting a string to an array.

22
00:01:09,047 --> 00:01:11,260
As we learned earlier in this class, a

23
00:01:11,260 --> 00:01:13,266
string is an iterable object because it's

24
00:01:13,266 --> 00:01:16,744
really just an array of characters. If we

25
00:01:16,744 --> 00:01:19,555
have a string, like on line 17, what we

26
00:01:19,555 --> 00:01:22,484
can do on line 19 is, we can say let

27
00:01:22,484 --> 00:01:26,708
values = …productNumber within square

28
00:01:26,708 --> 00:01:29,224
brackets. As you know, a square bracket

29
00:01:29,224 --> 00:01:31,518
represents an array. The spread operator

30
00:01:31,518 --> 00:01:34,504
iterates over that string and creates a

31
00:01:34,504 --> 00:01:37,540
single character out of each value and

32
00:01:37,540 --> 00:01:41,535
puts it into the values variable. Let's go

33
00:01:41,535 --> 00:01:44,829
ahead and run this. And there you can see

34
00:01:44,829 --> 00:01:47,091
the value comes out now into an array. So

35
00:01:47,091 --> 00:01:53,000
we took the string and converted it into an array using the spread operator.

