Array.indexOf(item) Last updated: 22. Jul 2024

Finds and returns index of specified item in an array.

Parameters

Name Type Description
item object Item to search for in array.

Returns

A number of the index (zero-indexed), -1 if item was not found.

Example

Data

{
"items" : [1, 2, 3]
}

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
Index of the number 3 is 2:
Test result: #items.indexOf(3)#

Output

The #JS code above produces the output shown below:
Index of the number 3 is 2:
Test result: 2