1
00:00:01,410 --> 00:00:06,870
I know we've mentioned array's quite a few times within the previous lessons, and we finally got to

2
00:00:06,870 --> 00:00:11,490
them and we are saving the best till last because arrays are really, really cool.

3
00:00:11,640 --> 00:00:14,350
I'm going to show you what they are and how you can use them.

4
00:00:14,550 --> 00:00:19,920
So just like objects, they give us the ability of a single variable and assign a bunch of values to

5
00:00:19,920 --> 00:00:24,180
it so that we can reference those values just with a single variable.

6
00:00:24,450 --> 00:00:30,270
So in this case, we've got shopping, but all of the contents of shopping, we have access to all that

7
00:00:30,270 --> 00:00:33,870
full list and then we can update change it as needed.

8
00:00:34,110 --> 00:00:40,250
We can also contain objects within arrays, arrays within arrays, so it can get fairly complex.

9
00:00:40,260 --> 00:00:45,120
We can use all the different data types as we've seen before, where we're using strings, we're using

10
00:00:45,120 --> 00:00:47,610
booleans numbers, null, undefined.

11
00:00:47,730 --> 00:00:54,390
So all of them are valid and they can all sit within the array in order to get valid values from the

12
00:00:54,390 --> 00:00:54,800
arrays.

13
00:00:54,800 --> 00:00:57,470
So they are zero based index values.

14
00:00:57,480 --> 00:01:05,250
So unlike what we saw with objects, arrays are limited to using the index value in order to retrieve

15
00:01:05,250 --> 00:01:09,270
back whatever value index value is associated with it.

16
00:01:09,510 --> 00:01:14,220
So we've got an example here where we're using the list we're referencing.

17
00:01:14,220 --> 00:01:19,770
We're trying to pull back item number three in the list, and that's where we're pulling back.

18
00:01:19,800 --> 00:01:21,450
So remember, it's starting at zero.

19
00:01:21,460 --> 00:01:24,330
So number three would be 35.

20
00:01:24,690 --> 00:01:27,420
And you can see that zero is Lowrance.

21
00:01:27,420 --> 00:01:31,940
One speaks to is true, three is 35.

22
00:01:32,130 --> 00:01:38,670
So using the array name and the index value, that's how we can retrieve values that are contained within

23
00:01:38,730 --> 00:01:39,250
that array.

24
00:01:39,630 --> 00:01:45,450
So the challenge for this lesson is to create an array with different types of data and then return

25
00:01:45,450 --> 00:01:48,300
the values of those different data types.

26
00:01:48,630 --> 00:01:52,740
So get the value into the console of the below array.

27
00:01:52,920 --> 00:01:58,220
We've got the default array called the list and there's a combination of that.

28
00:01:58,230 --> 00:01:59,430
There's an object in there.

29
00:01:59,430 --> 00:02:02,030
There's another array in there, there's a number.

30
00:02:02,070 --> 00:02:05,580
So there's all these different values that are contained in there.

31
00:02:05,700 --> 00:02:12,630
So the objective just to try it out and get 55 out, get to out, see how many times it takes you in

32
00:02:12,630 --> 00:02:14,720
order to retrieve back that information.

33
00:02:14,850 --> 00:02:17,610
And as you can see, two is a little bit tricky there.

34
00:02:17,860 --> 00:02:21,630
So this is going to be a little bit more of a challenge to put in the console.

35
00:02:21,840 --> 00:02:25,260
You can pause the video and I'll show you the solution coming up.

36
00:02:25,260 --> 00:02:31,140
And as well, this is a quick sneak peek at the solution will list out the list.

37
00:02:31,140 --> 00:02:34,020
And you can see that all of that information is contained.

38
00:02:34,320 --> 00:02:38,820
So what we want it to do is retrieve back some of the values that are contained in here.

39
00:02:38,970 --> 00:02:46,740
And in particular, we were looking to retrieve back 35 and number two there and also retrieve back

40
00:02:46,740 --> 00:02:47,550
55.

41
00:02:47,560 --> 00:02:49,740
So we want to get 55 and two.

42
00:02:49,950 --> 00:02:56,490
So those are two of the more complex ones, because the first one is contained within the object and

43
00:02:56,490 --> 00:02:58,640
the second one is contained within the array.

44
00:02:58,920 --> 00:03:00,690
So let's try it out within the console.

45
00:03:01,440 --> 00:03:08,210
And as you can see, when you are using the list, you can get the values back from the list.

46
00:03:08,730 --> 00:03:13,710
So using the index value so you can retrieve back the first first one.

47
00:03:13,710 --> 00:03:14,660
So zero based.

48
00:03:14,670 --> 00:03:15,300
Remember that.

49
00:03:15,540 --> 00:03:18,090
And then the second one is one.

50
00:03:18,330 --> 00:03:23,470
And you can go all the way through the entire list until you get to the one that you want to see.

51
00:03:23,760 --> 00:03:29,210
So if we were to list number six, this is where we retrieve back that object.

52
00:03:29,580 --> 00:03:34,830
So we've got a choice here where to retrieve back the score 55.

53
00:03:35,040 --> 00:03:39,780
We can use the list just as we set it, but we want to get score back.

54
00:03:39,930 --> 00:03:47,270
So we've got two choices because we've got an option to do it as a dot notation or a bracket notation.

55
00:03:47,520 --> 00:03:49,740
And as you can see, they're going to return back.

56
00:03:49,860 --> 00:03:52,050
So either one of these is correct.

57
00:03:52,290 --> 00:03:54,380
And let's type this into the console.

58
00:03:54,390 --> 00:03:57,840
So either one of these was a correct way to retrieve it back.

59
00:03:58,170 --> 00:04:03,770
And then the other object or another value that we want to retrieve back is coming from the list.

60
00:04:04,020 --> 00:04:07,580
And this one is going to be contained in number seven.

61
00:04:07,710 --> 00:04:11,260
And as you can see, this is an array that's contained within the array.

62
00:04:11,610 --> 00:04:14,820
So in order to retrieve back, the format is the same.

63
00:04:14,970 --> 00:04:18,350
So if we want to retrieve the second item, we do one.

64
00:04:18,360 --> 00:04:20,220
So retrieving it is the same way.

65
00:04:20,370 --> 00:04:25,920
And sometimes it does get fairly complex because you have to really dig through these and you'll see

66
00:04:25,920 --> 00:04:32,370
instances of arrays that contain objects and then objects that contain arrays again so they can get

67
00:04:32,370 --> 00:04:33,470
fairly complex.

68
00:04:33,660 --> 00:04:39,390
So it is important to practice and try it out and just make sure that you are able to retrieve back

69
00:04:39,390 --> 00:04:41,970
any one of the values contained within the list.
