Hello, in this jQuery video, I'm going to show you the in array method. So the inner array method, as you can probably already guess, allows you to check if something is in your array. So let's quickly we pop an array. And we'll say we'll call it epic array. And in JavaScript, you can put any sort of data type in the array. So let's pick up a number for my age, which is 27.
Put my superhero Batman, for one more favorite pizza. And to use the in array method, pretty simple. All we have to do is dollar.in array. And the first parameter that we pass through is what we're checking is in the array so we can So that's a 34. We know he has to be the exact same does cyber lock, just bear that in mind. And next we specify the array itself.
So epic array. If we were to reload our page, nothing will happen because we're not doing anything with this result. So let's just console log, console log. And we get zero. So this is saying zero because it's at index zero, as you can see the index zero. So if I were to duplicate that, and Batman.
Now if I reload it, I can say is, as you can see, it says index two. So remember, we've completed everything start at zero, so this will be index 01, and two, for the same. But instead of checking for 34, I check for, say the word ad, which clearly isn't In our array, if we reload, let's see what we get, we get minus one. So if you get a result of minus one because that is an invalid index, it means is not in your array. Another thing that you can do the last other thing you can do with the in array method is check if you have a particular element, but you know, after a specific index, so if I put say, I'm checking for pizza let's say the number two i know that i think it's a negative one even though pizza exists. This is index one.
I mean this is index 01. And two are showing this room now. is still same city mistake of meant to put the actual array first Then augment with the index. So it's what you're checking for the array name and the index and let me just run that again. So it is saying free. The reason it's returned index free is because it's at index three, like so.
So that's how you use the in array method led you to check if a certain value you got to make sure that the data type is the same. So 34 there is a number for do this, this is not the same thing. So make sure that they start with the same in array lady to check for a specific value in your array, really powerful. If you have any questions, feel free to shoot me a message. And as usual, I look forward to seeing you in the next video.