Sign In

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

FieldTypeRequiredDescription
Source Arraytemplate stringYesVariable 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

ValueBehavior
Sort by FieldOrders 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.

FieldTypeRequiredDescription
Sort KeytextNoObject 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.

ValueBehavior
Ascending (A-Z, 0-9)Smallest or earliest values first
Descending (Z-A, 9-0)Largest or latest values first

Defaults to Ascending.

Output

FieldTypeDescription
sortedarrayThe reordered array
countnumberNumber of items in the sorted array

Example

A database query returns a list of products. You want to display the most expensive items first:

  1. Add a Sort node after the data source.
  2. Set Source Array to nodes.httpRequest_1.body.products.
  3. Set Sort Mode to Sort by Field.
  4. Set Sort Key to price.
  5. 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.

On this page

Sort | Buildorado