Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

array.filter()

Filter an Array using a provided predicate.

Signature

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

Description

Returns an Array containing elements of 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:

  • Accepts an Array element as its only argument. You can pass in this argument using arrow function syntax.

  • Returns Boolean or Null.

If the predicate evaluates to true for an element, the element is included in the Array returned by the method.

Return value

Type Description

Array<Generic>

Array containing elements that evaluate to true for the provided predicate.

If no elements evaluate to true, the method returns an empty Array.

Examples

[1, 2, 3, 4, 5].filter((x) => {x == 1 || x == 4})
[
  1,
  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!