Sort
Sort an array of items by a field value in ascending or descending order, or shuffle them randomly.
The Sort node reorders the items in an array. You can sort by a specific object property in ascending or descending order, or shuffle the array into a random order. For arrays of primitive values (strings, numbers), leave the sort key empty to sort by the values themselves.
Configuration
Source Array
| Field | Type | Required | Description |
|---|---|---|---|
| Source Array | template string | Yes | Variable path to the array to sort, e.g. nodes.httpRequest_1.body.items |
The source must resolve to an array. If it resolves to a non-array value, the node fails with a NOT_ARRAY error.
Sort Mode
| Value | Behavior |
|---|---|
| Sort by Field | Orders items by a specified property and direction |
| Shuffle (Random) | Randomizes the array order using a Fisher-Yates shuffle |
Defaults to Sort by Field.
Sort Key
Only shown when Sort Mode is Sort by Field.
| Field | Type | Required | Description |
|---|---|---|---|
| Sort Key | text | No | Object property name to sort by (e.g. name, createdAt, amount). Leave empty to sort primitive values directly. |
Direction
Only shown when Sort Mode is Sort by Field.
| Value | Behavior |
|---|---|
| Ascending (A-Z, 0-9) | Smallest or earliest values first |
| Descending (Z-A, 9-0) | Largest or latest values first |
Defaults to Ascending.
Output
| Field | Type | Description |
|---|---|---|
| sorted | array | The reordered array |
| count | number | Number of items in the sorted array |
Example
A database query returns a list of products. You want to display the most expensive items first:
- Add a Sort node after the data source.
- Set Source Array to
nodes.httpRequest_1.body.products. - Set Sort Mode to Sort by Field.
- Set Sort Key to
price. - Set Direction to Descending.
The output at nodes.sort_1.sorted contains the products ordered from highest to lowest price.
To randomize a quiz question list, set Sort Mode to Shuffle (Random) instead. The sort key and direction fields are hidden in this mode.
See the Logic Nodes overview for a full list of available nodes.