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. |
Description
The order()
method creates a Array by applying an Ordering to the
values of this Array, and returns the new Array.
An Ordering is a method that takes one or more Ordering objects to sort
a Array. An Ordering object is created by using the asc()
or
desc()
function with a field accessor:
-
asc()
: sort by the field in ascending order -
desc()
: sort by the field in descending order
The first entry in the Ordering has the highest sorting priority, with priority decreasing with each following entry.
If order()
is the last value in a query, the first page of the new
Array is returned.
The source Array isn’t changed.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
ordering |
Ordering |
Ordering to apply to Array values. One or more Ordering objects. Ordering objects: |
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!