jQuery.inArray( value, array [, fromIndex ] )Returns: Number
Description: Search for a specified value within an array and return its index (or -1 if not found).
-
version added: 1.2jQuery.inArray( value, array [, fromIndex ] )
$.inArray()
method is similar to JavaScript's native .indexOf()
method in that it returns -1 when it doesn't find a match. If the first element within the array matches value
, $.inArray()
returns 0.
value
within array
, you need to check if it's not equal to (or greater than) -1.
-1
(not found) because a number is being searched in an array of strings:
1
|
|
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
|