Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

select

Category

Array / String

Arity

Binary<array|string> select <index>.

<array> select <index>
<string> select <index>

Description

Returns the element at the given zero-based index from an array, or the character at the given index from a string. Out-of-range index returns nil (no error thrown — matches Arma SQF behavior).

How It Works

  • Array: bounds-checks the index. Returns array[index]. O(1).
  • String: bounds-checks the index. Returns single-character string via string[index].ToString(). O(1).
  • Out of range: returns nil silently (no exception).

Usage

Array element access

_arr = ["a", "b", "c"];
_first = _arr select 0;          // "a"
_second = _arr select 1;         // "b"
_last = _arr select (count _arr - 1);  // "c"

_oob = _arr select 99;           // nil (out of range)

String character access

_name = "Arma";
_char0 = _name select 0;         // "A"
_char2 = _name select 2;         // "m"

Safe access with nil guard

_val = _arr select _index;
if (!isNil "_val") then {
    process(_val);
};

In loop

for "_i" from 0 to (count _arr - 1) do {
    _elem = _arr select _i;
    systemChat f"Element {_i}: {_elem}";
};

Thread Safety

ReadOnly — pure query. Safe from any scheduler.

See Also

  • count — array/string length
  • find — search for element
  • in — membership check
  • set — modify element at index
  • deleteAt — remove element at index

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally