array.where()

This method operates on an array. You typically fetch documents from a collection as a set, not an Array. For the equivalent Set method, see set instance methods.

For differences between Sets and Arrays, see Sets vs. Arrays.

Get the elements of an Array that match a provided predicate.

Signature

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

Description

Returns an Array of elements from the calling Array that match a provided predicate function.

The calling Array isn’t changed.

Parameters

Parameter Type Required Description

predicate

Predicate function

Yes

Anonymous predicate function that:

The method returns an Array of elements for which the predicate returns true.

Return value

Type Description

Array<Generic>

Array containing elements of the calling Array that match the predicate. If there are no matching elements, the Array is empty.

Examples

[1, 2, 3, 4].where(v => v > 2)
[
  3,
  4
]

See also

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!