---
name: "sort"
type: command
status: ok
groups: ["Arrays"]
arma3_since: "1.44"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/sort
revid: 377104
updated: 2026-01-01T10:00:38Z
---

# sort

*Command · Arrays · Arma 3 v1.44*

## Description

Attempts to sort given array either in ascending ([true](../commands/true.md)) or descending ([false](../commands/false.md)) order. 

> [!IMPORTANT]
> This will **modify** the original array!

## Syntax

```sqf
array sort order
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md) - array to be sorted, can also be a nested array.

  All array elements should be one of the following types:
  - [String](../topics/String.md) - Array of strings `["a","b","c"...]`
  - [Number](../topics/Number.md) - Array of numbers `[1,2,3...]`
  - [Array](../topics/Array.md) - Array of subarrays `[["a",1,2],["b",3,4],["c",5,6]...]`. Subarrays should be of the same structure. Subarray elements other than [String](../topics/String.md) or [Number](../topics/Number.md) will be ignored during sorting.
  Mixed arrays `["a",1,[true], ...]` are not supported and results are undefined.
- `order`: [Boolean](../topics/Boolean.md) - sorting order.
  - [true](../commands/true.md): ascending
  - [false](../commands/false.md): descending

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
_arr = [5.21725,1.30859,4,5.03028,1];
_arr sort true;
hint str _arr; //[1,1.30859,4,5.03028,5.21725]
```

### Example 2

```sqf
_dev = ["ja","pa","pa","tram","tara"];
_dev sort false;
hint str _dev; //["tram","tara","pa","pa","ja"]
```

### Example 3

```sqf
#define ASC true
#define DESC false
_scores = [[123,"bob",15],[123,"bill",20],[200,"dave",21],[200,"steve",11]];
_scores sort DESC;
hint str _scores; //[[200,"steve",11],[200,"dave",21],[123,"bob",15],[123,"bill",20]]
```

### Example 4

Sort buildings by distance and return position of the most distant building:

```sqf
_buildings = player nearObjects ["Land_Cargo_Patrol_V1_F", 500];
_buildings = _buildings apply { [_x distance player, _x] };
_buildings sort false;
hint format [
    "Most distant building is at %1, distance %2 m", 
    getPos (_buildings select 0 select 1),
    round (_buildings select 0 select 0)
];
```

## See also

[lbSortBy](../commands/lbSortBy.md) · [lnbSortBy](../commands/lnbSortBy.md) · [BIS_fnc_sortAlphabetically](../functions/BIS_fnc_sortAlphabetically.md) · [BIS_fnc_sortBy](../functions/BIS_fnc_sortBy.md) · [BIS_fnc_sortNum](../functions/BIS_fnc_sortNum.md)

## Community notes

**Killzone_Kid** — 2015-04-16

The algorithm for sorting subarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc.

<sub>Source: [BI Community Wiki — sort](https://community.bistudio.com/wiki/sort) (revision 377104).</sub>
