Use the array_sort_asc function to return a new array that contains all the elements of the input array, sorted in ascending order. This function is useful when you want to normalize the order of array elements for comparison, presentation, or further processing—such as identifying patterns, comparing sequences, or selecting boundary values.

You can apply array_sort_asc to arrays of numbers, strings, or dynamic objects, making it useful across many telemetry, logging, and security data scenarios.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.

Usage

Syntax

array_sort_asc(array)

Parameters

NameTypeRequiredDescription
arraydynamic✔️An array of values to sort. Can be numbers, strings, or other primitives.

Returns

A new array that contains the same elements as the input array, sorted in ascending order. If the input is not an array, the function returns an empty array.

Example

Query

['sample-http-logs']
| project sort = array_sort_asc(dynamic(['x', 'a', 'm', 'o', 'i']))

Run in Playground

Output

[
  [
    "a",
    "i",
    "m",
    "o",
    "x"
  ]
]
  • array_index_of: Returns the position of an element in an array. Use after sorting to find where values fall.
  • array_length: Returns the number of elements in an array. Use to understand array size before or after sorting.
  • array_slice: Returns a subrange of the array. Useful after sorting to get top-N or bottom-N elements.
  • array_sort_desc: Sorts array elements in descending order. Use when you need reverse ordering.