/

HTML / CSS / JavaScript Tutorial

JavaScript Array method: indexOf()

[this page | pdf | back links]

The indexOf() method (when applied to a JavaScript array) returns the index of the first element of an array found when an array is searched.

 

It has the following syntax with the following parameters. It returns a number as above (or -1 if no array element passes the test).

 

array.indexOf(item, start)

 

Parameter

Required / Optional

Description

item

Required

Item to search for

start

Optional

Index value at which to start search. Negative values indicate start from a position counting back from the end and then search to the end

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Arrays


Desktop view | Switch to Mobile