1 00:00:00,000 --> 00:00:09,820 [MUSIC] 2 00:00:09,820 --> 00:00:14,700 Arrays can contain strings, numbers, Booleans, and other types. 3 00:00:14,700 --> 00:00:17,770 Arrays can also hold any combination of values. 4 00:00:17,770 --> 00:00:22,300 For example, an array might have the string Hello in the first position, 5 00:00:22,300 --> 00:00:26,810 the number 23 in the second, and the value true in the third position. 6 00:00:26,810 --> 00:00:29,990 In fact, you can place an array within an array, 7 00:00:29,990 --> 00:00:33,740 even create an array that contains nothing but other arrays. 8 00:00:33,740 --> 00:00:38,890 An array inside an array is called a multidimensional or two dimensional array. 9 00:00:38,890 --> 00:00:43,032 That might sound a bit strange and confusing right now, but you can start to 10 00:00:43,032 --> 00:00:46,873 think of a multidimensional array as a list containing other lists. 11 00:00:46,873 --> 00:00:50,625 You can picture a two-dimensional array as a spreadsheet. 12 00:00:50,625 --> 00:00:55,170 Think of the spreadsheet as the master list, a list containing other lists. 13 00:00:55,170 --> 00:00:59,280 The data in the spreadsheet is organized into rows and columns. 14 00:00:59,280 --> 00:01:04,780 Each row represents one array or one of the arrays inside the master array. 15 00:01:04,780 --> 00:01:08,840 And each column cell represents one element in an array. 16 00:01:08,840 --> 00:01:13,040 For example, you might use an array to store the grades of multiple students. 17 00:01:13,040 --> 00:01:16,070 Let's say three students took four tests. 18 00:01:16,070 --> 00:01:21,376 Each row represents one student, and each column is one test score. 19 00:01:21,376 --> 00:01:25,699 For instance, the first row represents Student 1, and 20 00:01:25,699 --> 00:01:29,940 their test scores are 80, 90, 100, and 95. 21 00:01:29,940 --> 00:01:33,973 The second student's scores appear in the second row, and 22 00:01:33,973 --> 00:01:37,452 their scores are 75, 95, 85, and 100. 23 00:01:37,452 --> 00:01:39,710 The third student's test scores are in the last row. 24 00:01:40,710 --> 00:01:43,310 You've probably seen data like this in a spreadsheet. 25 00:01:43,310 --> 00:01:47,310 So what would this look like as a multidimensional array in JavaScript? 26 00:01:47,310 --> 00:01:51,860 You start by creating an array, then at elements inside the array, 27 00:01:51,860 --> 00:01:54,160 each element is another array. 28 00:01:54,160 --> 00:01:57,190 You'd add the first student's grades like this. 29 00:01:57,190 --> 00:02:00,020 Notice that there's another set of square brackets, 30 00:02:00,020 --> 00:02:03,910 which indicates that there's an array nested inside the array. 31 00:02:03,910 --> 00:02:08,050 You add the next set of student grades by adding a comma and another array. 32 00:02:08,050 --> 00:02:12,670 Another comma and another nested array adds the last student's grades. 33 00:02:12,670 --> 00:02:15,850 Now, how do you access these different sets of grades? 34 00:02:15,850 --> 00:02:20,390 First, let's start with how you get the grades for an individual student. 35 00:02:20,390 --> 00:02:25,070 Since each set of student grades is one element in the grades array, 36 00:02:25,070 --> 00:02:28,250 you use the index notation you learned about earlier. 37 00:02:28,250 --> 00:02:31,540 For example, the first student's grades are at grades[0], 38 00:02:31,540 --> 00:02:34,610 the first element in the grades array. 39 00:02:34,610 --> 00:02:38,830 The second student's grades are in the second element, at index position 1. 40 00:02:38,830 --> 00:02:42,120 And the third student's grades are at grades[2]. 41 00:02:42,120 --> 00:02:46,070 Because each of those index values represents another array, 42 00:02:46,070 --> 00:02:50,040 you can access an element in a nested array using another index value. 43 00:02:51,080 --> 00:02:51,970 For example, 44 00:02:51,970 --> 00:02:57,470 the first array of student grades is that index position 0 of the outer array. 45 00:02:57,470 --> 00:03:02,030 To access the last grade in that first nested array, chain a second 46 00:03:02,030 --> 00:03:07,440 set of square brackets holding the index value of the last element, like this. 47 00:03:07,440 --> 00:03:10,660 Now, how would you get to the first grade of the last student? 48 00:03:10,660 --> 00:03:14,718 Well, that grade is in the last nested array, which is at index 2 and 49 00:03:14,718 --> 00:03:17,760 position 0 of that array. 50 00:03:17,760 --> 00:03:21,680 This example uses arrays of numbers to represent student grades. 51 00:03:21,680 --> 00:03:25,810 But you can create a multidimensional array containing lists of any value, 52 00:03:25,810 --> 00:03:27,950 strings, numbers and Booleans, for instance.