Skip to main content

Array Sort

This node reorders an array based on values.

The Array Sort node creates a sorted copy of an input array.

The Array Sort node takes an array and sorts its items based on a specific property (Key Path). It supports ascending and descending order and handles numbers and strings correctly.

Inputs

Input

DataDescription
ArrayThe source array to sort.

Object Options

DataDescription
Key PathThe property key to sort by (e.g., "price", "date", "name"). Required for object arrays.

Sort Options

DataDescription
AscendingBoolean. true for A-Z / 0-9. false for Z-A / 9-0. Default: true.

Actions

SignalDescription
DoTriggers the sort operation.

Outputs

Data

DataDescription
Sorted ArrayThe resulting sorted array.

Signals

SignalDescription
DoneTriggered when the sort is complete.

Usage

Use this node to organize lists for display.

Example Use Cases

  1. Leaderboard: Sort players by "score", Ascending = false (highest first).
  2. Product List: Sort by "price", Ascending = true (cheapest first).
  3. Alphabetical: Sort by "name".

Detailed Behavior

  1. Type Handling:
    • Numbers: Sorted numerically (1, 2, 10).
    • Strings: Sorted alphabetically using locale comparison ("a", "b", "c").
  2. Stability: The sort is generally stable (items with equal sort values maintain their relative order).
  3. New Collection: Creates a new collection; does not mutate the original array.

Troubleshooting

  • Sorting Numbers as Strings: If your numbers are stored as strings ("10", "2"), they might sort alphabetically ("10", "2"). Ensure your data types are correct upstream.