where()

Get a subarray of matching Array values.

Signature

where(predicate: () => Boolean | Null): Array<T>

Description

The where() method returns the subarray of Array values that match the predicate Function. The predicate Function must return a Boolean or Null.

If where() is the last value in a query, the first page of the created Array is returned.

Parameters

Parameter Type Required Description

predicate

Function

Yes

Anonymous Function that compares Array values and returns true for matches or false for mismatches, or Null.

Return value

Type Description

Array<Any>

Array representing the Array values that match the predicate Function.

Examples

Get all People documents with age less than 80:

[1, 2, 3, 4].where(v => v > 2)
[
  3,
  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!