jQuery.inArray(value, array[, fromIndex]) (alias $.inArray) searches an array for a value with strict equality (since jQuery 1.2). It returns the index, or -1 if the value is missing.
Syntax
Start with these common calls. Keep them short and readable.
Learn jQuery.inArray(): find a value’s index in an array, handle -1 when missing, use fromIndex, strict equality pitfalls, compare with indexOf and includes, examples, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Have an array (or array-like list) to search.
Step 2
Call $.inArray(value, array).
Step 3
If the result is -1, the value was not found.
Return Value
Return Value
Description
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
Start at 2. The third argument skips indexes 0 and 1.
Missed."Pete" is already behind the start point.
Frequently Asked Questions
jQuery.inArray(value, array[, fromIndex]) searches an array for value using strict equality (===). It returns the zero-based index where value is found, or -1 if it is not present.
Same convention as Array.prototype.indexOf: -1 means not found. Check membership with $.inArray(val, arr) !== -1 — never with a plain if ($.inArray(...)), because index 0 is found but falsy.
Both use strict equality and return -1 when missing. indexOf is a native Array method. inArray is a jQuery static utility that also works on array-like objects with length and indexed values.
When provided, the search starts at that index instead of 0. Useful for later occurrences. If the value only appears before fromIndex, the result is -1.
Strict equality (===). The number 10 and the string "10" are different — $.inArray(10, ["8", "9", "10"]) returns -1.
Use $.inArray() when you need the index, or when you already use jQuery with array-like input. Use includes() for a simple true/false membership check on real arrays in modern JavaScript.
Yes, if jQuery is loaded. It is a data utility and does not need a DOM. Many Node projects prefer native indexOf or includes instead.