Skip to content

pushBack

ffredyk edited this page Jul 23, 2026 · 1 revision

pushBack

Category

Array

Arity

Binary<array> pushBack <element>.

<array> pushBack <any>

Description

Appends a single element to the end of the array. Returns the index at which the element was inserted (the new last index). This matches Arma SQF pushBack behavior.

Thread Safety: Not thread-safe. Array must belong to current scheduler.

How It Works

Adds the element to the underlying List<Value>, then returns Count - 1 (the index of the newly added element). The array grows by 1.

Usage

Basic push

_arr = [1, 2, 3];
_idx = _arr pushBack 4;        // returns 3, _arr is [1,2,3,4]
_arr pushBack 5;               // _arr is [1,2,3,4,5]

Building arrays dynamically

_enemies = [];
{
    if (_x get "side" == "east") then {
        _enemies pushBack _x;
    };
} forEach _allUnits;

Ignore return value

_queue pushBack _newTask;      // just append, don't need index

Chain with return

_arr = [];
_lastIdx = _arr pushBack "first";   // 0
_lastIdx = _arr pushBack "second";  // 1

Thread Safety

Not thread-safe. Array must be owned by the current scheduler. Use freeze for cross-scheduler sharing, or sendTo to transfer ownership.

See Also

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