Now, thanks to jQuery we have a javascript alternative for PHP’s in_array function.

Let’s have an array:

var my_array = ["I", "love", "", 99];

It will work with mixed arrays as you can see in the example above.
Now, let’s do a few searches:

var pos1 = jQuery.inArray("love", my_array);

It will return 1, since this is the index of the 2nd position.

var pos2 = jQuery.inArray("hawai", my_array);

This will return -1 because the ‘hawai’ string is not found.

var pos3 = jQuery.inArray(99, my_array);

This will return 3, the index of the 4th element.

The function returns the index of the found element, if the element is not found it will return -1.