1 00:00:01,740 --> 00:00:06,930 In this on a race, we're going to talk about the spread operator, which is something of a fairly recent 2 00:00:06,930 --> 00:00:12,570 development in JavaScript, and it can cause some confusion because it's not immediately clear what 3 00:00:12,570 --> 00:00:13,050 it does. 4 00:00:14,370 --> 00:00:15,210 So let's take a look. 5 00:00:16,920 --> 00:00:22,650 So what a sprint operator does is to create an array for misapprehend for the array spread operator. 6 00:00:23,190 --> 00:00:28,650 So that's going to do is break apart the array into its individual components. 7 00:00:29,790 --> 00:00:36,600 So if I say if I have it in array called Operand and the sprint operators, dot, dot, dot, I can 8 00:00:36,600 --> 00:00:43,290 create a new array using dot, dot, dot operand because with operand does is breaks the array into 9 00:00:43,290 --> 00:00:44,520 its individual elements. 10 00:00:44,880 --> 00:00:49,710 And then because I put the square brackets around it, it puts it back into being a new array. 11 00:00:50,280 --> 00:00:55,050 So this is a way to clone an array and I'll explain what that means in the second. 12 00:00:58,020 --> 00:01:02,370 So we're going to Pandoras together using the same methodology, five three arrays. 13 00:01:02,400 --> 00:01:08,100 I can say dot, dot, dot array, one comma, dot, dot, dot array two comma, dot, dot, dot, array 14 00:01:08,110 --> 00:01:08,520 three. 15 00:01:10,950 --> 00:01:15,030 And then anything you can iterate through, you can turn it into an array. 16 00:01:16,830 --> 00:01:22,350 So, for example, if I have my string and I put dot, dot, dot in front of it, it's going to turn 17 00:01:22,350 --> 00:01:25,730 it into a ray of Amcom, like I'm esq, et cetera. 18 00:01:28,520 --> 00:01:35,750 And then an example from the math library is, if I want to find the minimum value in an array, I can 19 00:01:35,750 --> 00:01:42,710 use the spread operator because what the minimum does is it takes a list of numbers separated by commas, 20 00:01:43,490 --> 00:01:45,370 and so you can't pass an array to it. 21 00:01:45,410 --> 00:01:49,430 So what you do is use the spread operator to break it into its individual elements. 22 00:01:51,500 --> 00:01:58,130 So with all that said, and it's confusing, but hopefully we can clear it up a little bit by doing 23 00:01:58,130 --> 00:01:58,910 some examples. 24 00:02:01,070 --> 00:02:02,570 All right, let's start with an array. 25 00:02:05,180 --> 00:02:12,680 And first, let me talk about what cloning is and why it's useful if I say let my array 26 00:02:15,410 --> 00:02:28,640 equals two, four, six, eight, 10, and then I say let the other array equals my array. 27 00:02:30,320 --> 00:02:31,990 We have made a copy of the array. 28 00:02:32,840 --> 00:02:35,270 We are just using the same array with a different variable. 29 00:02:35,870 --> 00:02:46,580 So if I say other array, so two equals 200 and then I logout my array, 30 00:02:51,200 --> 00:02:53,930 we're going to see that other array changed my array. 31 00:02:56,510 --> 00:02:57,440 So let's run that. 32 00:03:00,060 --> 00:03:05,850 So we see other ouray now has the value of two hundred, so Meira also has that because when we did 33 00:03:05,850 --> 00:03:10,500 this, all we did was a copy, the start of the raid, a pointer to the array. 34 00:03:11,520 --> 00:03:14,790 So with the spread operator, does it lets us create a new array. 35 00:03:16,200 --> 00:03:19,350 So let's do this again, except then use the spread operator. 36 00:03:20,190 --> 00:03:22,630 And I say dot, dot, dot my array. 37 00:03:24,150 --> 00:03:27,480 Now, before we get that far, what's the dot, dot, dot. 38 00:03:28,090 --> 00:03:30,660 So I'm just gonna say cancel that log. 39 00:03:31,230 --> 00:03:38,180 I thought that my oray and let's comment this other stuff out for right now. 40 00:03:44,020 --> 00:03:50,710 So until you do this, it's hard to understand with the dot, dot, dot spread operator does, but all 41 00:03:50,770 --> 00:03:53,260 it does is breaks it up into individual numbers. 42 00:03:54,270 --> 00:04:01,700 So this is just like we have five variables and one variable holds two, one variable, four, et cetera. 43 00:04:03,720 --> 00:04:06,000 All right, let's uncommented this. 44 00:04:10,630 --> 00:04:15,940 So now other ready when we sign at the 200 mile race, still going to have two, four, six, eight, 45 00:04:15,940 --> 00:04:16,270 10. 46 00:04:18,290 --> 00:04:19,940 So let's put them both 47 00:04:24,200 --> 00:04:24,740 and run it. 48 00:04:28,900 --> 00:04:32,950 So other Arae has the 200, but my race has six. 49 00:04:34,540 --> 00:04:38,890 So what we've done is made a copy of what's in the array, all right. 50 00:04:39,230 --> 00:04:41,160 And this honestly just takes practice. 51 00:04:41,170 --> 00:04:45,020 You just have to get used to using it and then it starts to make sense. 52 00:04:45,970 --> 00:04:47,340 So let's do the concatenation now. 53 00:04:47,350 --> 00:05:02,320 We have to raise so say let one more array equals dot, dot, dot, Myra, dot, dot, dot, other array. 54 00:05:05,020 --> 00:05:05,860 Got that. 55 00:05:06,910 --> 00:05:08,230 And we'll give it even one more round. 56 00:05:08,240 --> 00:05:11,050 We'll put some strings in this one if you see 57 00:05:13,660 --> 00:05:14,340 the F 58 00:05:17,080 --> 00:05:18,720 and then we'll cancel all this out. 59 00:05:23,840 --> 00:05:29,240 One more Arae, so let's see what that has. 60 00:05:33,640 --> 00:05:39,120 So it's got all these first two arrays in one array plus as ABC and D.F. elements. 61 00:05:40,090 --> 00:05:41,290 So what is concatenated? 62 00:05:41,290 --> 00:05:42,340 Three arrays together? 63 00:05:42,340 --> 00:05:43,220 Very simple. 64 00:05:43,990 --> 00:05:45,430 And then the math thought men. 65 00:05:47,230 --> 00:05:48,160 Let's take a look at that. 66 00:05:49,510 --> 00:05:53,140 So if we have let's look at math men first. 67 00:05:56,270 --> 00:05:59,030 So it gets us the minimum value of a set of values. 68 00:06:00,710 --> 00:06:10,370 So what this allows you to do is send in a set of values to get a man so I can say to come forward, 69 00:06:10,370 --> 00:06:10,940 come a six. 70 00:06:10,940 --> 00:06:11,480 Come eight. 71 00:06:13,310 --> 00:06:13,940 Come on one. 72 00:06:21,970 --> 00:06:23,110 So what's up with that? 73 00:06:27,000 --> 00:06:34,440 So our method then returns one, but if we have an array, it's a little bit more handy to be able to 74 00:06:34,440 --> 00:06:37,400 use the spread operator if I just put an array in here. 75 00:06:43,640 --> 00:06:50,630 We get not a number, which is what NASA stands for, because the array is not a number, it's an array. 76 00:06:52,010 --> 00:06:56,900 So what we need to do is use the spread operator to break it up into its individual elements. 77 00:07:00,650 --> 00:07:02,060 Now we get a list of numbers. 78 00:07:04,170 --> 00:07:06,480 And so we get to examine. 79 00:07:08,430 --> 00:07:14,040 All right, so that's the spread operator, and all I can say is you got to practice and get used to 80 00:07:14,040 --> 00:07:19,500 it so that when a need comes up for it, you think, oh, that's a good use for the spread operator. 81 00:07:20,730 --> 00:07:27,210 So we'll be talking about this more later and destruction is next, and that is sort of similar.