1 00:00:01,080 --> 00:00:05,769 So far, you've learned useful array methods like push, pop, shift, and 2 00:00:05,769 --> 00:00:06,440 unshift. 3 00:00:06,440 --> 00:00:10,242 These are just a few out of the dozens of array methods available. 4 00:00:10,242 --> 00:00:14,240 As you gain more experience with arrays, you'll want to start learning and 5 00:00:14,240 --> 00:00:16,933 experimenting with other more advanced methods. 6 00:00:16,933 --> 00:00:22,511 So in these next couple of videos, I'll teach you other common and 7 00:00:22,511 --> 00:00:28,510 useful array methods, join(), includes(), and indexOf(). 8 00:00:28,510 --> 00:00:30,032 You don't need to follow along just yet. 9 00:00:30,032 --> 00:00:32,892 You will get to do some programming with these methods soon. 10 00:00:32,892 --> 00:00:36,941 You can also review the code examples from this video in the teacher's notes. 11 00:00:36,941 --> 00:00:38,980 Let's first look at the join method. 12 00:00:41,270 --> 00:00:45,983 The join method takes an array and returns a string holding all the elements in 13 00:00:45,983 --> 00:00:50,422 the array, separated by a supplied character, like a comma or a colon. 14 00:00:50,422 --> 00:00:54,992 This is a great way to display all of the items in an array on a single line. 15 00:00:54,992 --> 00:00:58,528 For example, here I have an array named daysInWeek, 16 00:00:58,528 --> 00:01:00,738 holding all the days in the week. 17 00:01:00,738 --> 00:01:05,720 I can convert this array into a single comma-separated 18 00:01:05,720 --> 00:01:10,174 string by calling the join method on daysInWeek. 19 00:01:10,174 --> 00:01:16,430 In the JavaScript console, I'll type daysInWeek.join(). 20 00:01:16,430 --> 00:01:21,429 Notice how this returns one string with all the daysInWeek array elements 21 00:01:21,429 --> 00:01:24,582 joined and separated by a comma, by default. 22 00:01:24,582 --> 00:01:27,302 You'll usually pass the join method a string, 23 00:01:27,302 --> 00:01:32,130 specifying the character you want to separate the elements of the array. 24 00:01:32,130 --> 00:01:35,703 You can pass any character to the join method, like a comma, 25 00:01:35,703 --> 00:01:37,888 colon, semicolon, even a letter. 26 00:01:37,888 --> 00:01:40,452 In fact, you can pass more than one character. 27 00:01:40,452 --> 00:01:45,081 For example, you can pass a string containing a comma and a space. 28 00:01:45,081 --> 00:01:50,160 The comma and space appear after each element in the array, except the last one. 29 00:01:51,220 --> 00:01:56,688 To separate each with a space, you'd pass join a string with a space in it. 30 00:02:01,992 --> 00:02:07,490 Another array method that's extremely useful is the includes method. 31 00:02:07,490 --> 00:02:11,899 includes determines whether an array includes a certain value 32 00:02:11,899 --> 00:02:15,733 among its entries, and returns either true or false. 33 00:02:15,733 --> 00:02:20,261 If the value you passed to the includes method is in the list of array elements, 34 00:02:20,261 --> 00:02:21,713 includes returns true. 35 00:02:21,713 --> 00:02:26,532 If the value is not in the array, it returns false. 36 00:02:26,532 --> 00:02:30,160 For example, here I have a fruit array. 37 00:02:30,160 --> 00:02:35,502 I can search if apple is in the array with the includes method, 38 00:02:35,502 --> 00:02:39,532 by typing fruit.includes the string apple. 39 00:02:39,532 --> 00:02:40,994 This returns true, 40 00:02:40,994 --> 00:02:45,471 because the string apple is indeed a value in the fruit array. 41 00:02:45,471 --> 00:02:49,853 If I pass includes the string pear, it returns false, 42 00:02:49,853 --> 00:02:54,450 because pear is not a value in the fruit array. 43 00:02:54,450 --> 00:02:58,313 Keep in mind that includes is case-sensitive, so it treats uppercase and 44 00:02:58,313 --> 00:03:00,292 lowercase characters differently. 45 00:03:00,292 --> 00:03:04,470 For example, if I pass includes Apple with a capital A, it returns false. 46 00:03:07,110 --> 00:03:11,500 Finally, you can use the indexOf method to return the index or 47 00:03:11,500 --> 00:03:14,382 position of an element inside an array. 48 00:03:14,382 --> 00:03:21,050 For example, apple is the first element in the fruit array, 49 00:03:21,050 --> 00:03:28,254 so fruit.indexOf('apple') returns its index value, 0. 50 00:03:28,254 --> 00:03:32,801 If I pass it grapefruit, indexOf returns the value 2, 51 00:03:32,801 --> 00:03:36,882 since that's the index position of grapefruit. 52 00:03:36,882 --> 00:03:42,464 Let's see what happens if the value passed indexOf is not in the array, 53 00:03:42,464 --> 00:03:46,105 for instance fruit.indexOf('pear'). 54 00:03:49,210 --> 00:03:51,501 Pear is not in the fruit array, 55 00:03:51,501 --> 00:03:55,746 so notice how the indexOf method returns the value -1. 56 00:03:55,746 --> 00:04:00,703 And if I pass it kiwi, it also returns -1. 57 00:04:00,703 --> 00:04:07,557 indexOf returns -1 only when it cannot find the index of an element. 58 00:04:07,557 --> 00:04:11,123 You can learn why it's -1 in the teacher's notes with this video. 59 00:04:11,123 --> 00:04:14,880 And while you're there, check out other handy array methods you might come across.