indexOf()

Get the array index of the first element that matches the given value.

Signature

indexOf(value: Any): Number
indexOf(value: Any, index: Number ): Number

Description

The indexOf() method searches, left-to-right, for the element that matches value and returns the index of the element if a match is found.

If the optional index is included, the method searches right-to-left starting at index and returns the matching index, inclusive.

Parameters

Parameter Type Required Description

value

Any

Yes

Value to search for in the array elements.

index

Number

Starting location of a right-to-left search.

Return value

Type Description

Number

Index of element that matches value or null if a match isn’t found.

Examples

['a', 'b', 'c', 'b'].indexOf('c')
2

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!