array.indexWhere()

Get the index of an Array element that matches the given predicate.

Signature

indexWhere(predicate: () => Boolean | Null) => Number | Null

indexWhere(predicate: () => Boolean | Null, start: Number) => Number | Null

Description

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

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

Parameters

Parameter Type Required Description

predicate

Function

Yes

Function that tests for a matching element.

start

Number

Starting location of a right-to-left search.

Return value

Type Description

Number

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

Examples

['a', 'b', 'c', 'b'].indexWhere(v => v == '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!