Array node

Array Sort

Sort array elements in ascending or descending order. Outputs the sorted array, the original indices in their new positions, and the element count. Numeric values are sorted numerically; strings are sorted alphabetically.

Inputs

PortTypeDefault
ArrayThe list to order. Numbers sort by value and text alphabetically; anything else passes through untouched.any—
OrderAscending or descending. Only 1 means descending — every other value sorts ascending.int0

Outputs

PortType
Resultany
Indicesany
Countint

How It Works

Array Sort reorders elements based on the Order parameter:

  • 0 — Ascending: Smallest to largest (A to Z for strings).
  • 1 — Descending: Largest to smallest (Z to A for strings).

The Indices output contains the original positions of each element in their new sorted order. This is useful for tracking which element moved where — for example, to sort a parallel array of labels to match a sorted array of values.

Use Cases

  • Ranking: Sort sensor readings to find top performers or rank channels by activity.
  • Data visualization: Sort values before plotting to create ordered bar charts or ranked displays.
  • Parallel array sorting: Use the Indices output to reorder a second array (labels, colors) to match the sorted data.
  • Median preparation: Sort before accessing the middle element (though Array Stats computes median directly).

Tips

  • The Indices output maps new positions to old positions: Indices[0] tells you which original element is now first.
  • For complete statistics including median, use Array Stats — it handles sorting internally.
  • Mixed-type arrays sort numeric values first, then strings.

Open Array Sort in the interactive catalog →

Array Sort is one of 381 nodes in Grafit Pro.

Free download. Every feature for 7 days, no card. Then €99.99 once — or keep playing your projects as a Player.

More Array nodes