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.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.
Description
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 |
One or more sorting criteria, separated by commas. Each criterion is a read-only anonymous
function, optionally wrapped in If neither The anonymous function is passed each Array element as an argument. |
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!