Skip to content

arraySort - Sorts array according to arguments

The arraySort function will sort an array acccording to some arguments, and return the sorted array.

Syntax

arraySort(array: array<T>, desc: bool?, nullsFirst: bool?): array<T>

Arguments

NameTypeRequiredDescription
arrayarray of type TtrueT must be either string, bool, number, interval, timestamp, regexp or enum
descboolfalsewhen true, the array is sorted in reverse (descending) order. Must be a literal. Defaults to false
nullsFirstboolfalsewhen true, nulls will appear at the start of the output. Must be a literal. Defaults to false

Example - Sorting names by alphabetical order

Consider the following document:

{
    "names": ["Chris", "John", "Adam", "Jose"]
}

Sorting these names by alphabetical order is straight forward:

replace names with names.arraySort()

This results in the following document:

{
    "names": ["Adam", "Chris", "John", "Jose"]
}