---
title: "sort array by field · RUAL Documentation"
description: "Sorts the elements of an array by a given key."
canonical: https://docs.rual.nl/block-types/array/array_sort_condition
language: en
---

# sort array by field

This block is part of the [`array`](https://docs.rual.nl/block-types/array) group and was last modified in core [`v10.4.28`](https://docs.rual.nl/core-versions/100428).

Sorts the elements of an array by a given key.

- Array required `array` The array to be sorted.

- sort by `value` Sort by the given field. If left empty, it will sort the entire array.

- A-Z / 1-9 required `condition` If true: sort the array in ascending order (A-Z or 1-9). • Hidden when other fields are filled

- Z-A / 9-1 required `condition` Display-only counterpart of `asc`: this pin is not read. Sorting is descending whenever `asc` is false or left unwired. • Hidden when other fields are filled

- Array `array` The sorted array.

Stable-sorts a COPY of the array; the input is not mutated. With sort_by set it sorts object items by that dot-path field, otherwise by the elements themselves. Direction is decided ONLY by the asc pin: true sorts ascending, unfilled or false sorts DESCENDING (the desc pin is display-only). Numbers compare numerically, strings lexicographically ("10" before "2"), a number and a numeric string compare numerically, and null sorts as smallest.

A typical wiring for [sort array by field](https://docs.rual.nl/block-types/array/array_sort_condition): [true](https://docs.rual.nl/block-types/condition/condition_is_true) feeds the `asc` pin; [group by](https://docs.rual.nl/block-types/array/array_group_by) feeds the `array` pin; [value](https://docs.rual.nl/block-types/value/value_default) feeds the `sort_by` pin; [==](https://docs.rual.nl/block-types/condition/condition_equal) feeds the `desc` pin; the `array` out pin feeds [join](https://docs.rual.nl/block-types/array/array_join).

![Studio canvas example for the sort array by field block: typical wiring for sort array by field.](https://docs.rual.nl/canvas-examples/array_sort_condition.png)

### Commonly used with

In production blueprints, this block is most often wired together with:

- [true](https://docs.rual.nl/block-types/condition/condition_is_true): feeds into this block. Gives the condition true hard-coded.

- [group by](https://docs.rual.nl/block-types/array/array_group_by): feeds into this block. Groups the elements of the given array by a specified field.

- [join](https://docs.rual.nl/block-types/array/array_join): this block feeds into it. Creates and returns a new string by concatenating all of the elements in this array, separated by void if none provided.

- [splice](https://docs.rual.nl/block-types/array/array_splice): this block feeds into it. Removes an item from your given array.

- [create](https://docs.rual.nl/block-types/globals/trigger_custom_function): feeds into this block. Creates a new function that can be executed using the given name.

- [value](https://docs.rual.nl/block-types/value/value_default): feeds into this block. Simply returns the provided value.

### Version history

Introduced in [`v10.4.28`](https://docs.rual.nl/core-versions/100428).
