array.order()

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.

Sort an Array's elements.

Signature

order(ordering: ...(A => Any) & {}) => Array<A>

Description

Creates a sorted Array by applying one or more sorting criteria to the calling Array.

You define each sorting criterion by wrapping asc() (ascending) or desc() (descending) around a read-only anonymous function.

The first criterion has the highest sorting priority, with priority decreasing for each subsequent criterion.

The calling Array remains unchanged.

Parameters

Parameter Type Required Description

ordering

Generic

One or more sorting criteria, separated by commas.

Each criterion is a read-only anonymous function, optionally wrapped in asc() (ascending) or desc() (descending) to indicate sort order.

If neither asc() or desc() is provided, asc() is used by default.

The anonymous function is passed each Array element as an argument.

Return value

Type Description

Array<Generic>

New Array with elements in requested order.

Examples

Order the Array elements returned by the function in ascending order.

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