# array_sort_asc



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.

## Usage [#usage]

### Syntax [#syntax]

```kusto
array_sort_asc(array)
```

### Parameters [#parameters]

| Name  | Type    | Required | Description                                                               |
| ----- | ------- | -------- | ------------------------------------------------------------------------- |
| array | dynamic | ✓        | An array of values to sort. Can be numbers, strings, or other primitives. |

### Returns [#returns]

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

## Example [#example]

**Query**

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

[Run in Playground](https://play.axiom.co/axiom-play-qf1k/query?initForm=%7B%22apl%22%3A%22%5B'sample-http-logs'%5D%20%7C%20project%20sort%20%3D%20array_sort_asc\(dynamic\(%5B'x'%2C%20'a'%2C%20'm'%2C%20'o'%2C%20'i'%5D\)\)%22%7D)

**Output**

```json
[
  [
    "a",
    "i",
    "m",
    "o",
    "x"
  ]
]
```

## List of related functions [#list-of-related-functions]

* [array\_index\_of](/apl/scalar-functions/array-functions/array-index-of): Returns the position of an element in an array. Use after sorting to find where values fall.
* [array\_length](/apl/scalar-functions/array-functions/array-length): Returns the number of elements in an array. Use to understand array size before or after sorting.
* [array\_slice](/apl/scalar-functions/array-functions/array-slice): Returns a subrange of the array. Useful after sorting to get top-N or bottom-N elements.
* [array\_sort\_desc](/apl/scalar-functions/array-functions/array-sort-desc): Sorts array elements in descending order. Use when you need reverse ordering.

## Other query languages [#other-query-languages]

<LanguageComparisons>
  <Accordion title="Splunk SPL users">
    In Splunk SPL, arrays are typically handled through `mvsort`, which sorts multivalue fields in ascending order. In APL, `array_sort_asc` provides similar functionality but works on dynamic arrays and returns a new sorted array.

    <CodeGroup>
      ```sql Splunk example
      | eval sorted_values = mvsort(multivalue_field)
      ```

      ```kusto APL equivalent
      datatable(arr: dynamic)
      [
        dynamic([4, 2, 5])
      ]
      | extend sorted_arr = array_sort_asc(arr)
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="ANSI SQL users">
    ANSI SQL does not directly support array data types or array sorting. You typically normalize arrays with `UNNEST` and sort the results using `ORDER BY`. In APL, you can sort arrays inline using `array_sort_asc`, which is more concise and expressive.

    <CodeGroup>
      ```sql SQL example
      SELECT val
      FROM UNNEST([4, 2, 5]) AS val
      ORDER BY val ASC
      ```

      ```kusto APL equivalent
      print sorted_arr = array_sort_asc(dynamic([4, 2, 5]))
      ```
    </CodeGroup>
  </Accordion>
</LanguageComparisons>
