Sort List | ARRAY_SORT
Syntax
ARRAY_SORT( [value], [direction = 1] )
Parameters
value
An ARRAY to sort.
direction optional
Set whether to sort in ascending or descending order.
If the value is a NUMBER that is greater than or equal to 0, sorting will be done in ascending order.
If the value is a NUMBER that is less than 0, sorting will done in descending order.
If the value is not a NUMBER, sorting will be done in ascending order.
Return Value
Returns a sorted copy of the VALUE.Description
Sort the items in an ARRAY. Comparison for the sort is done structurally. If values of different types are provided, the comparison is done by type with the following precedence (from lowest to highest):- UNDEFINED
- NULL
- BOOLEAN
- NUMBER
- STRING
- DATE
- ARRAY / LIST
- OBJECT / MAP
Examples
ARRAY_SORT(null) # returns []
# VALUE is [
# '1', '2', 1, 1, 2, '3', '3'
# ]
ARRAY_SORT(VALUE)
# returns [
# 1, 1, 2, '1', '2', '3', '3'
# ]
ARRAY values are sorted structurally.
# VALUE is [
# [1, 2, 3],
# [1, 3, 2],
# [1, 2, 4],
# [1, 2, 3, 0]
# ]
ARRAY_SORT(VALUE)
# returns [
# [1, 2, 3],
# [1, 2, 3, 0],
# [1, 2, 4]
# [1, 3, 4]
# ]