instance method Array#indexOf
Array#indexOf(item[, offset = 0]) → Number
-
item
(?
) – A value that may or may not be in the array. -
offset
(Number
) – The number of initial items to skip before beginning the search.
Returns the index of the first occurrence of item
within the array,
or -1
if item
doesn't exist in the array. Array#indexOf
compares
items using strict equality (===
).
Array#indexOf
acts as an ECMAScript 5 polyfill.
It is only defined if not already present in the user's browser, and it
is meant to behave like the native version as much as possible. Consult
the ES5 specification for more
information.
Examples
[3, 5, 6, 1, 20].indexOf(1) // -> 3 [3, 5, 6, 1, 20].indexOf(90) // -> -1 (not found) ['1', '2', '3'].indexOf(1); // -> -1 (not found, 1 !== '1')