Description: Finds the specified value in the array and returns its index (1 if not found).
Jquery.inarray (value, array [, FromIndex])
-
Value
Type: anything
The value to find.
-
Array
Type: Array
An array through which to find.
-
FromIndex
Type: Number
An array index value that represents where to start the lookup. The default value is 0, which finds the entire array.
The $.inarray () method is similar to the native. IndexOf () method of JavaScript, which returns 1 when no matching element is found. If the first element of the array matches the value (parameter), then $.inarray () returns 0.
Because JavaScript treats 0 as false (that is, 0 = = False, but 0!== false), to check if value exists in the array, you need to check if it is not equal to (or greater than)-1.
Comparisons between values are strictly compared (fool's Wharf Note: that is, = = = or!== comparison). The following code returns 1 (not found) because it is not possible to find a number in a string array:
$.inarray (5 + 5, ["8", "9", "10", 10 + ""]); -1
Jquery.inarray (value, array [, FromIndex])