---
name: "select"
type: command
status: ok
groups: ["Arrays", "Strings", "Config"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/select
revid: 377134
updated: 2026-01-01T10:27:32Z
---

# select

*Command · Arrays, Strings, Config · Arma 3 v0.50 · introduced in Operation Flashpoint v1.00*

## Description

Selects an element from an array, config entry from [Config](../topics/Config.md) or substring from a string or a range from an array.

## Syntax

### Syntax 1

```sqf
array select index
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `index`: [Number](../topics/Number.md) - index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up.

  Arma 3 v2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element.

**Returns:** [Anything](../topics/Anything.md) - a reference to the array element given by its index

> [!IMPORTANT]
> When the index equals the size of the array, there is no error for out of range selection and [nil](../commands/nil.md) is returned - see [#Example 8](../commands/select.md#example-8).

### Syntax 2

```sqf
array select boolean
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `boolean`: [Boolean](../topics/Boolean.md) - [false](../commands/false.md) selects the **first** element of the [Array](../topics/Array.md), [true](../commands/true.md) the **second** one

**Returns:** [Anything](../topics/Anything.md) - a reference to the array element

### Syntax 3

*since arma1 1.00*

```sqf
config select index
```

**Parameters:**

- `config`: [Config](../topics/Config.md)
- `index`: [Number](../topics/Number.md) - index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up

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

### Syntax 4

*since arma3 1.28*

```sqf
string select [start, length]
```

**Parameters:**

- `string`: [String](../topics/String.md)
- `start`: [Number](../topics/Number.md) - string position to start selection from. 0 denotes the first character of the string, 1 the second, etc. If passed number has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up
- `length`: [Number](../topics/Number.md) - (Optional, default *string*'s length) number of characters to select

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

> [!NOTE]
> Substring version of [select](../commands/select.md) operates with the ANSI charset; if Unicode support is desired, see [forceUnicode](../commands/forceUnicode.md).

### Syntax 5

*since arma3 1.32*

```sqf
array select [start, count]
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `start`: [Number](../topics/Number.md) - array index to start selection from
- `count`: [Number](../topics/Number.md) - (Optional after Arma 3 v2.14) number of array elements to select. If the selected range exceeds source array boundaries, selection will be made up to the last element of the array.

  > [!NOTE]
  > Since v2.14 'count' is optional, if omitted the selection is made from *start* until the end of the array.

**Returns:** [Array](../topics/Array.md) - a new array from selection

### Syntax 6

*since arma3 1.56*

```sqf
array select expression
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `expression`: [Code](../topics/Code.md) - expression that is expected to return [Boolean](../topics/Boolean.md) or [Nothing](../topics/Nothing.md).
  If [true](../commands/true.md) is returned, the original array value of currently tested element [_x](../topics/Magic_Variables.md#x) will be added to the output array

**Returns:** [Array](../topics/Array.md) - a new array of all elements from the original array that satisfied expression condition

## Examples

### Example 1

```sqf
["a", "b", "c", "d"] select 2;    // result is "c"
position player select 2;        // result is Z coordinate of player position
```

### Example 2

```sqf
["", currentWeapon player] select alive player; // if player is dead, "" is selected
```

### Example 3

```sqf
(configFile >> "cfgVehicles" >> typeOf vehicle player >> "Turrets") select 0 >> "gunnerAction";
```

### Example 4

```sqf
hint str ("japa is the man!" select [8]);        // the man!
hint str ("japa is the man!" select [0, 7]);    // japa is
```

### Example 5

```sqf
hint str ([1,2,3,4,5,6] select [1, 4]); // [2,3,4,5]
```

### Example 6

```sqf
_even = [1,2,3,4,5,6,7,8,9,0] select { _x % 2 == 0 }; // returns [2, 4, 6, 8, 0]
```

### Example 7

JavaScript endsWith() alternative:

```sqf
private _fnc_endsWith = 
{
    params ["_string", "_endswith"];
    _string select [count _string - count _endswith] isEqualTo _endswith
};

["Arma 3", "3"] call _fnc_endsWith; // true
["Arma 3", "4"] call _fnc_endsWith; // false
```

### Example 8

[select](../commands/select.md) index traps:

```sqf
private _array = ["a", "b", "c", "d"];
_array select 0; // "a"
_array select 3; // "d"
_array select 4; // nil - no error shown
_array select 5; // error

// can sometimes be useful
private _firstEnemyNearMe = units opfor select { player distance _x < 10 } select 0; // nil if no enemies nearby
if (isNil "_firstEnemyNearMe") exitWith { systemChat "no enemy found" };
systemChat format ["enemy found: %1", name _firstEnemyNearMe];

// get the last element properly
_array select (count _array);        // wrong - nil is returned
_array select (count _array - 1);    // correct - "d" is returned
```

### Example 9

> [!NOTE]
> **Arma 3:** Since Arma 3 v2.12 `-1` can be used to select the last element of an array.

```sqf
private _array = [1, 2, 3, 4, 5];
hint str (_array select -1); // 5
```

## See also

[a hash b](../commands/a_hash_b.md) · [selectRandom](../commands/selectRandom.md) · [selectRandomWeighted](../commands/selectRandomWeighted.md) · [set](../commands/set.md) · [resize](../commands/resize.md) · [reverse](../commands/reverse.md) · [in](../commands/in.md) · [find](../commands/find.md) · [findIf](../commands/findIf.md) · [toArray](../commands/toArray.md) · [toString](../commands/toString.md) · [forEach](../commands/forEach.md) · [count](../commands/count.md) · [deleteAt](../commands/deleteAt.md) · [deleteRange](../commands/deleteRange.md) · [append](../commands/append.md) · [sort](../commands/sort.md) · [param](../commands/param.md) · [params](../commands/params.md) · [splitString](../commands/splitString.md) · [joinString](../commands/joinString.md) · [pushBack](../commands/pushBack.md) · [pushBackUnique](../commands/pushBackUnique.md) · [apply](../commands/apply.md) · [forceUnicode](../commands/forceUnicode.md)

## Community notes

**General Barron** — 2009-03-03

When combined with the [count](../commands/count.md) command, this can be used to read all entries out of a config; even when you don't know exactly how many entries there will be.
See the notes under [count](../commands/count.md) for more info.

---

**Killzone_Kid** — 2013-09-28

Rounding of fractions with [select](../commands/select.md) is not the same as when you use [round](../commands/round.md) command:

```sqf
_roundThis = 0.5;
hint str ([0,1] select _roundThis);            // 0
hint str ([0,1] select round _roundThis);    // 1
```

---

**Pierre MGI** — 2016-07-14

You can substract array from array using select:

```sqf
_array = [[1], [2], [3]];
_sub = [2];
_array - _sub; // [[1], [2], [3]]
_array select { !(_x isEqualTo _sub) }; // [[1], [3]]
[[1],[2],[2],[2],[2],[3]] select { !(_x isEqualTo _sub) }; // [[1], [3]]
```

---

**Commy2** — 2016-11-12

It is not safe to escape the code block of alternative syntax #5 with [exitWith](../commands/exitWith.md), [breakOut](../commands/breakOut.md) etc:

```sqf
x3 = [1,2,3,4,5] select {
    if (_x == 3) exitWith
    {
        false;
    };
    true
};
// could be expected to be: x3 = [1,2,4,5]
// actual result: x3 = false
```

---

**Igneous01** — 2017-02-14

[#Syntax 5](../commands/select.md#syntax-5) is the equivalent of passing in a predicate that returns a boolean. In SQF, a piece of code will always return what the last executed command returned.

```sqf
myAliveUnits = allUnits select { alive _x };    // alive returns a boolean, the last statement run was alive _x,
                                                // therefore this piece of code will return a true/false to the select command
myEastGroups = allGroups select { side _x == east };                    // returns all east groups
my4ManGroups = allGroups select { count units _x == 4 };                // returns all groups that have 4 men in them
unitsThatDetectedMe = allUnits select { _x knowsAbout player > 0.1 };    // returns a list of units that have detected the player
```

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