How to check if array contains specific element?

Posted by nikola, With 0 Comments, Category: JavaScript && jQuery, Tags:

You can use jQuery's inArray function.

Ie, to check if array myArray contains number 10 in it, you can use next code:

if ($.inArray( myArray, 10) !== -1) {
 alert("Yes, array myArray contains number 10 as one of it's elements!");
 } else {
 alert("Nope, array myArray doesn't contains number 10!");
 }