ORDER
Sort a list

Description

Sorts a list using a formula that is evaluated for each item in the list. Returns the sorted list.
The formula should result to a comparable value (a text or a number) that is used to determine the order of the items. By default the items are sorted in ascending order. By providing the 3rd parameter you can choose the direction.
If multiple values have the same ordering value, their original order will be preserved.
Note that for text values, the ordering is case-sensitive. If you want a case-insensitive ordering, you may for example wrap your ordering formula with LOWERCASE function.

Function signature

1
ORDER(list: Array, sortingcriteria: Function, sortdirection: String = asc) => Array
Copied!
Parameter
Description
List
List of items to sort
Sorting criteria
Formula evaluated for each item in the list, used to determine the ordering value for the item
Sort direction
Direction of the ordering. Use either "asc" meaning ascending order (smallest first) or "desc" meaning descending order (greatest first).

Examples

1
animals = [
2
{
3
"name": "dog",
4
"weight": 123
5
},
6
{
7
"name": "cat",
8
"weight": 48
9
},
10
{
11
"name": "rat",
12
"weight": 10
13
},
14
{
15
"name": "pig",
16
"weight": 123
17
}
18
]
Copied!
Formula
Return value
ORDER(animals, item.weight)
[{"name":"rat","weight":10},{"name":"cat","weight":48},{"name":"dog","weight":123},{"name":"pig","weight":123}]
ORDER(animals, item.weight, "desc")
[{"name":"dog","weight":123},{"name":"pig","weight":123},{"name":"cat","weight":48},{"name":"rat","weight":10}]
ORDER<animal>(animals, animal.weight, "asc")
[{"name":"rat","weight":10},{"name":"cat","weight":48},{"name":"dog","weight":123},{"name":"pig","weight":123}]
Last modified 1yr ago
Export as PDF
Copy link