indexOf

indexOf(value) -> position

Returns the position of the first occurrence of the argument within the array. If the argument doesn’t exist in the array, returns -1.

Prior to version 1.6, Prototype’s Array#indexOf checked for equivalence (==) instead of identity (===). This was changed in order to be compliant with emerging browser implementations of Array#indexOf.

Minor note: this uses a plain old optimized indexing loop, so there’s no risk of extensions being detected by this method.

Example


[3, 5, 6, 1, 20].indexOf(1)
// -> 3

[3, 5, 6, 1, 20].indexOf(90)
// -> -1

// COMPATIBILITY CHANGE:
[0, false, 15].indexOf(false)
// Prototype 1.5 returns 0 (because 0 == false)
// Prototype 1.6 returns 1 (because 0 !== false)