set.lastWhere()

Get the last element that matches the given predicate.

Signature

lastWhere(predicate: Boolean | Null) => Any | Null

Description

The lastWhere() method gets the last element that matches the predicate function.

Parameters

Parameter Type Required Description

predicate

Boolean

Yes

Boolean function that tests every element and returns elements that match the predicate.

Return value

Type Description

Boolean

Element found by predicate or null if no elements match.

Examples

// `toSet()` converts an Array to a Set.
let set = [1, 2, 3, 4].toSet()
set.lastWhere(v => v > 2)
4

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!