# Sort Array

### What It Does

Arranges items in a list in a specific order, either ascending or descending. It can sort by a specific property for complex objects, helping to organize collections.

### Inputs

| Name   | Description                                    | Type | Required |
| ------ | ---------------------------------------------- | ---- | -------- |
| array  | The list to be sorted                          | List | Yes      |
| order  | Direction of sort ("asc" or "desc")            | Text | No       |
| sortBy | Property name to sort by (for object elements) | Text | Yes      |

### Outputs

| Name  | Description     | Type |
| ----- | --------------- | ---- |
| value | The sorted list | List |

![Sort Array Example](https://3657049418-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy0SFXZjN1sdgdxYM7QPE%2Fuploads%2FmonEsa8tM927tKgWf68n%2FScreenshot%202025-04-17%20at%206.37.35%E2%80%AFPM.png?alt=media\&token=e71e670e-9141-4a26-b024-7ff7bd266378)

### How to Use It

1. Drag the Sort Array node into your graph.
2. Connect your list (like `[16, 18, 21, 24, 28, 32]`) to the "array" input.
3. Set "sortBy" to the property to sort on (e.g., "value").
4. Optionally change "order" to "desc" for descending order (default is "asc").

<figure><img src="https://3657049418-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy0SFXZjN1sdgdxYM7QPE%2Fuploads%2FqRI1xShzHq4YZytUlwqs%2FCleanShot%202025-05-07%20at%2019.50.45%402x.png?alt=media&#x26;token=1a279561-db2b-4e20-9bcc-bfd724106501" alt=""><figcaption></figcaption></figure>

### Tips

* For simple lists (numbers or strings), use an empty string for the "sortBy" value.
* The sort is stable, meaning equal items maintain their relative order.

### See Also

* [**Reverse Array**](https://documentation.tokens.studio/graph-engine/available-nodes/array/reverse-array): For simply flipping the order of items without sorting.
* [**Array Filter**](https://documentation.tokens.studio/graph-engine/available-nodes/array/filter): For selecting items rather than reordering them.

### Use Cases

* **Color Organization**: Sort colors by brightness, hue, or other properties.
* **Token Prioritization**: Arrange design tokens by their importance or frequency of use.
* **Size Sequencing**: Order spacing or sizing tokens from smallest to largest for consistent scales.
