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.
Pass the value, the array, and optionally where to start.
Have an array (or array-like list) to search.
Call $.inArray(value, array).
If the result is -1, the value was not found.
To start later in the list, pass fromIndex as the third argument.
Piece
Required?
Role
value
Yes
Value to search for (strict ===)
array
Yes
Array (or array-like) to search
fromIndex
No
Start index (default 0)
Return
—
Index number, or -1
Pseudocode
Pseudocode
function inArray(value, array, fromIndex):
start = fromIndex or 0
for i from start to array.length - 1:
if array[i] === value: // strict equality
return i
return -1
// Membership check (safe):
found = inArray(value, array) !== -1
Reference
Cheat Sheet
Keep these facts handy while searching arrays with jQuery.
Strict.10 === "10" is false, so the first search fails.
Match types. Searching for "10" finds index 2.
Edge Cases & Pitfalls
Check these before using indexes in real code.
falsy
Never treat the index as a boolean
0 == false in loose checks. Always write !== -1 (or > -1) for membership.
strict
Types must match
4 and "4" are different. Normalize types before you search if your data is mixed.
fromIndex
Earlier matches are skipped
A value can exist in the array and still return -1 if it only appears before fromIndex.
native
Prefer native helpers in modern JS
Use indexOf for indexes and includes for boolean checks on true arrays. Keep $.inArray in jQuery-heavy code.
Compatibility
Browser Support
jQuery.inArray() is a data utility available since jQuery 1.2+ in all browsers that load jQuery. It does not need a special DOM API — only jQuery.
✓ jQuery 1.2+ · All browsers with jQuery
jQuery.inArray()
Works wherever jQuery runs in the browser. For modern pure-array code, Array.prototype.indexOf and includes are the native alternatives.
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$.inArray()Browsers
Bottom line: Use $.inArray(val, arr) in jQuery apps. Use arr.indexOf(val) or arr.includes(val) for native arrays.
Analysis
Performance Notes
Approach
Cost
Best for
$.inArray(val, arr)
O(n)
Small/medium lists
arr.indexOf(val)
O(n)
Native arrays
Set.has(val)
O(1) avg
Many membership checks
Linear scan is fine for typical UI arrays. If you check membership thousands of times on the same list, build a Set once instead of repeating inArray.
Remember
Key Takeaways
Role:$.inArray(val, arr) → index or -1.
Membership: always compare with !== -1.
Strict: types must match (===).
fromIndex: search can skip earlier matches.
One line: use $.inArray for a strict index lookup — treat -1 as missing, and never treat 0 as false.
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.