jQuery Check If Value Exists in Array: We bring an short tutorial to check an specific value found in array or not in jQuery.
For this we can use jQuery.inArray() method to check value exist in associative array or not. This is a in-built jQuery method to find specific value in array element. If value exist then it return its index and if not found value then return -1.
How to Use jQuery.inArray() method:
For example we create an associative array.
1 |
var arrColor = ['red', 'blue', 'yellow', 'green']; |
Let’s write jQuery code to check value exist in array or not.
1 2 3 4 5 6 7 8 |
if ($.inArray('yellow', arrColor) >= 0) { alert('Value found in Array'); } else { alert('Value Not found'); } |