SORT sorts a collection by the values returned from applying a sorting function to each element in the collection.

Function category: Text


SORT(arg1, arg2)




A collection.


Sorting function that will be applied to each element of the collection


Example 1: Sort prices by numerical value

Let's say we're given a response with the following vehicle information:

"fleet_prices":[16000, 17450, 9200],
"fleet_names": ["BMW", "Audi", "Mercedes Benz"]

If we want to organize those prices by basic numerical value, we can use SORT with the dynamic references themselves serving as a sorting function:

SORT(data.fleet_prices, _)

This returns the following:

[9200, 16000, 17450]

Example 2: Sort strings using same arguments

We can also sort strings using SORT:

SORT(data.fleet_names, _)

This results in the following:

["Audi", "BMW", "Mercedes Benz"]

Example 3: Sort using a dynamic reference

We can also apply a function to the dynamic reference:

SORT(data.fleet_names, LEN(_))

This results in the following:

["Mercedes Benz", "Audi", "BMW",]