1 00:00:00,000 --> 00:00:09,425 [MUSIC] 2 00:00:09,425 --> 00:00:12,942 Hey what's up, my name is Dustin, and I'm a developer here at Treehouse. 3 00:00:12,942 --> 00:00:17,493 Today, I wanna take you through using the JavaScript array method known as includes. 4 00:00:17,493 --> 00:00:22,088 As the name suggests, this method checks if an array includes a specific value and 5 00:00:22,088 --> 00:00:24,233 returns true or false respectively. 6 00:00:24,233 --> 00:00:26,764 Let's hop into some code and see how this works. 7 00:00:26,764 --> 00:00:30,094 Make sure to check out the description or teacher's notes down below for 8 00:00:30,094 --> 00:00:31,083 related resources. 9 00:00:31,083 --> 00:00:33,343 If you're ready, let's get into it. 10 00:00:33,343 --> 00:00:37,511 First, let's check out the official MDN documentation for this method. 11 00:00:37,511 --> 00:00:38,919 It's pretty straightforward. 12 00:00:38,919 --> 00:00:43,622 According to MDN, the includes method determines whether an array includes 13 00:00:43,622 --> 00:00:48,338 a certain value among its entries, returning true or false as appropriate. 14 00:00:48,338 --> 00:00:49,868 Sounds pretty simple. 15 00:00:49,868 --> 00:00:51,238 Let's practice it a bit. 16 00:00:51,238 --> 00:00:54,788 I'll open up my text editor with an empty app.js file, and 17 00:00:54,788 --> 00:00:56,637 I'll run this file with Node. 18 00:00:56,637 --> 00:00:59,837 If you're unfamiliar with Node or don't have it installed, 19 00:00:59,837 --> 00:01:02,982 you can run this code in your browser's developer console. 20 00:01:02,982 --> 00:01:07,095 Let's set up a brand new array, I'll call this names and we'll throw in some names. 21 00:01:07,095 --> 00:01:09,690 Let's write jamie, kandra, and taylor. 22 00:01:17,859 --> 00:01:21,939 Underneath our array, let's write a console.log method, and 23 00:01:21,939 --> 00:01:26,704 inside of that we can write our names array and chain on our includes method. 24 00:01:26,704 --> 00:01:30,537 Inside of our includes method, let's write the string bob. 25 00:01:30,537 --> 00:01:34,590 If I hit save and open up our terminal and write node app.js, 26 00:01:34,590 --> 00:01:36,667 you'll see we get back false. 27 00:01:36,667 --> 00:01:39,925 And this is because bob does not appear in our array. 28 00:01:39,925 --> 00:01:42,250 Let's change bob with kandra. 29 00:01:42,250 --> 00:01:46,407 I'll hit save and run node app.js in my terminal again, and 30 00:01:46,407 --> 00:01:48,292 this time we get back true. 31 00:01:48,292 --> 00:01:51,015 This is because kandra appears in our array. 32 00:01:51,015 --> 00:01:55,023 This method is really straightforward but can also do some complex things. 33 00:01:55,023 --> 00:01:59,435 I'll link below a video where I use the includes method to create 34 00:01:59,435 --> 00:02:02,140 a dynamic search feature for a web app. 35 00:02:04,550 --> 00:02:07,751 And that about covers it for the includes JavaScript array method. 36 00:02:07,751 --> 00:02:10,231 I hope this guide helped and I'll see you in the next one. 37 00:02:10,231 --> 00:02:13,850 Until then, have fun and happy coding.