The index of the array at which to begin the search. The default is 0, which will search the whole array.

The $.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.

Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), to check for the presence of value within array, you need to check if it's not equal to (or greater than) -1.

The comparison between values is strict. The following will return -1 (not found) because a number is being searched in an array of strings:

1

$.inArray( 5 + 5, [ "8", "9", "10", 10 + "" ] );

Example:

Report the index of some elements in the array.

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

<!doctype html>

<htmllang="en">

<head>

<metacharset="utf-8">

<title>jQuery.inArray demo</title>

<style>

div{

color: blue;

}

span{

color: red;

}

</style>

<scriptsrc="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>

<div>"John" found at <span></span></div>

<div>4 found at <span></span></div>

<div>"Karl" not found, so <span></span></div>

<div>"Pete" is in the array, but not at or after index 2, so <span></span></div>