> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.itential.com/itential-platform/2023-2/studio/tasks/reference/sort/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server. # sort > Reference for the sort workflow task, which sorts the elements of an array in ascending or descending order. ## Task purpose The `sort` task sorts the elements of a given array and returns the sorted array. The default sort order is ascending (A to Z, 0 to 9). This task modifies the position of elements in the original array. ## Potential use case Use `sort` to arrange a list of names in alphabetical order, sort a collection of dates numerically, or order any array of numbers, strings, or objects. ## Properties | Incoming | Type | Description | | --------- | ------- | ----------------------------------------------------------------------------- | | `arr` | Array | Required. The array to sort. | | `key` | String | Optional. For arrays of objects, the property key to sort by. | | `limit` | Number | Optional. The maximum number of records to return. | | `reverse` | Boolean | Required. If `true`, sorts in descending order. Default: `false` (ascending). | | Outgoing | Type | Description | | ---------- | ----- | ----------------- | | `response` | Array | The sorted array. | ## Examples ### Example 1 In this example: * `arr` is statically set to `[{"name":"cat"},{"name":"dog"},{"name":"hamster"},{"name":"ant"},{"name":"Lion"}]`. Note that `"Lion"` begins with an uppercase letter. * `key` is `name` and `limit` is `4`. * `reverse` is `false` (default — ascending order). ![](/_fern-img/73950ce228cf92817f248afdc6cfc1bf5f8aa2bcf2be238568e4ab6112af891a.webp) The result is ascending order, with `"Lion"` listed first because uppercase letters sort before lowercase letters. ![](/_fern-img/c10fe7b47ed1f8da2ecfd780b1356c7543d186cd0dd4464b0f0da0a893431a98.webp) ### Example 2 In this example: * `arr` is statically set to `[{"car":"Audi"},{"car":"Volvo"},{"car":"Honda"},{"car":"BMW"}]`. All names begin with uppercase letters. * `key` is `car` and `limit` is left blank. * `reverse` is `false` (default — ascending order). ![](/_fern-img/52d434405615b911bc8be67e4b69e2496f98efc1193019007499d173a0eeeea3.webp) The result is alphabetical (ascending) order. ![](/_fern-img/1f0c3107a14e73a058250c650b0e09783e46a8c560c83adf1328ea7d3695b2bb.webp) ### Example 3 In this example: * `arr` is statically set to `["ant","bee","Cat","dog","Elephant"]`. The values mix lowercase and uppercase. * `key` and `limit` are left blank. * `reverse` is `true` (descending order). ![](/_fern-img/4e45a1a4eea07eb7f8e40bb186e19ed8e90112bd47884431dcf7d729d7dfbc08.webp) The result is descending order, with all lowercase values in reverse alphabetical order followed by the uppercase values. ![](/_fern-img/9092f63d6617dadad105f0bcd2a15789ac5c98a1aeaf4f2ecf4c68ac11bc50aa.webp) > Reference for the sort workflow task, which sorts the elements of an array in ascending or descending order.