About Pi Downloads Documentation Plugins Developer Forum Issues

Array.indexOf

Summary

Return the first index at which a given element can be found in the array, or -1 if it is not present.(It's just created on old browsers which haven't got this method natively)

Syntax

Array.indexOf(value)

Example

>>> var list = [3,5,7,9]
>>> list.indexOf(3)
0

Examples

Example #1: Create an array and find an item's index.

Source files of the above example:

../../examples/indexOf.js

var fruits = ['Apple','Cherry','Grape','Banana'];
document.write(fruits.indexOf("Grape"));

See Also