1 00:00:00,510 --> 00:00:06,420 Welcome back to Learn to Code and JavaScript and this lecture, when I start looking at a raise for 2 00:00:06,430 --> 00:00:08,940 next four lectures, I'm going to look at arrays, including this one. 3 00:00:09,450 --> 00:00:11,400 The first two are going to be pretty basic. 4 00:00:11,430 --> 00:00:13,200 The next two are going to be a little bit more advanced. 5 00:00:13,620 --> 00:00:16,410 So it's possible you may want to skip the second two until later. 6 00:00:17,340 --> 00:00:18,770 So anyway, let's get into arrays. 7 00:00:20,160 --> 00:00:25,650 What always give us they're a collection of values and the values do not have to be the same type in 8 00:00:25,650 --> 00:00:26,300 JavaScript. 9 00:00:27,240 --> 00:00:30,900 So think of what we know so far, which is variables. 10 00:00:31,470 --> 00:00:33,990 So it's kind of boring to say that I have a name. 11 00:00:34,920 --> 00:00:36,080 I can't do much with it. 12 00:00:36,600 --> 00:00:40,690 What I might want to do is have 100 names and do something with all 100 of them. 13 00:00:41,280 --> 00:00:43,290 So this is what arrays allow you to do. 14 00:00:45,680 --> 00:00:52,280 So you have a very literals Nerdfighteria square brackets with the values separated by commas so it 15 00:00:52,280 --> 00:00:56,660 could look like this Mirae equals square bracket one comma three. 16 00:00:56,660 --> 00:01:00,830 Come a five, come on seven, come in line in the square brackets, semicolon. 17 00:01:01,850 --> 00:01:02,960 Or it could look like this. 18 00:01:03,390 --> 00:01:04,700 You don't have to be the same types. 19 00:01:05,330 --> 00:01:07,870 Another day equals five comma. 20 00:01:07,880 --> 00:01:09,370 Hello cometrue. 21 00:01:10,070 --> 00:01:11,930 So this area has three different types. 22 00:01:13,970 --> 00:01:17,250 Array elements are then accessed by zero based index. 23 00:01:18,470 --> 00:01:29,660 So in our example with my array, my array index one or people say sub one, the value is three because 24 00:01:30,230 --> 00:01:32,360 the zero value is number one. 25 00:01:32,930 --> 00:01:34,630 The number one value is number three. 26 00:01:35,570 --> 00:01:40,070 And this is a lot like strings of recall string characters are zero based. 27 00:01:41,750 --> 00:01:49,910 You can update a value in an array so I can say my array index or my razib two equals fifty five. 28 00:01:50,880 --> 00:01:59,400 So this replaces the five with 55 and then an array length property like string length can give you 29 00:01:59,400 --> 00:02:01,180 the number of elements in the array. 30 00:02:03,120 --> 00:02:06,280 So the actual array length can't be changed once it's initialized. 31 00:02:06,300 --> 00:02:10,680 But there are certain methods that return an array with a different length. 32 00:02:11,620 --> 00:02:12,710 So we'll take a look at those. 33 00:02:13,540 --> 00:02:19,300 So let's look at some examples of initializing a raise and making use of the values in an array. 34 00:02:20,500 --> 00:02:25,930 So here's our starting application, so let's do a few things with the race so array variables are defined 35 00:02:25,930 --> 00:02:28,720 like other variables you use left or const. 36 00:02:29,650 --> 00:02:37,780 So I can say let my array equals to come before a comma six, comma eight. 37 00:02:39,040 --> 00:02:42,030 And now this array will have five elements with those values. 38 00:02:42,760 --> 00:02:44,980 So if I just cancel, log out an array 39 00:02:49,240 --> 00:02:50,140 and the length. 40 00:02:55,500 --> 00:02:56,220 Here's what we get. 41 00:03:01,130 --> 00:03:07,370 So I can see that already tells me the length in parentheses, so the council tells me that and if I 42 00:03:07,370 --> 00:03:11,910 open up a little a little triangle, it will expand the element. 43 00:03:11,940 --> 00:03:15,440 So if there is a thousand elements that will show them to me on the first one. 44 00:03:16,970 --> 00:03:21,680 And then my life is out here and you see the life is built into the ray. 45 00:03:22,800 --> 00:03:24,830 So it's listed in there as well. 46 00:03:27,240 --> 00:03:29,370 So let's make a change. 47 00:03:35,070 --> 00:03:38,790 Two equals five thousand. 48 00:03:41,210 --> 00:03:43,490 And we will just copy this. 49 00:03:50,300 --> 00:03:56,300 And run it, so now our number five has been replaced by 5000 in the array. 50 00:03:57,350 --> 00:04:09,890 I can reassign a new array to the array so I can say my array equals Hello World. 51 00:04:11,850 --> 00:04:12,590 Twenty three. 52 00:04:16,080 --> 00:04:22,560 And then when we come to work that out, we'll have the Nuray, so keep in mind, this is a totally 53 00:04:22,560 --> 00:04:23,520 distinct array. 54 00:04:24,660 --> 00:04:28,470 Then the array that we created up here only has three elements. 55 00:04:29,010 --> 00:04:30,450 It's got two strings, one number. 56 00:04:35,640 --> 00:04:36,870 A world 23. 57 00:04:40,090 --> 00:04:45,670 All right, so that's an introduction to initializing an array and manipulating it. 58 00:04:46,120 --> 00:04:48,570 So next, we're going to look at some selected array methods.