Arma 3 Scripting

Command in Arrays

pushBack

Also available as Markdown and JSON, or read the original wiki page.

Description

Insert an element to the back of the given array. This command modifies the original array. (see also: pushBackUnique)

Syntax

array pushBack element

Parameters:

Returns: Number - index of inserted element

Examples

Example 1

_arr = [1,2,3];
_arr pushBack 4;
hint str _arr; //[1,2,3,4]

Example 2

_arr = [1,[2,4],3];
(_arr select 1) pushBack [5,6];
hint str _arr //[1,[2,4,[5,6]],3]

See also

pushBackUnique · select · set · resize · reverse · count · find · in · forEach · deleteAt · deleteRange · append · sort · arrayIntersect · apply · BIS_fnc_arrayPushStack · BIS_fnc_arrayPush

Community notes

ffur2007slx2_5

(A3 1.26) It is recommended to use pushBack instead of BIS_fnc_arrayPush.

_array = [1,2,3];
_array pushBack 4; //same as [_array, 4] call BIS_fnc_arrayPush;
Skaronator

It's highly recommended to use the new pushBack command, up to 43% faster than set and up to 11843% faster a plus b!

Killzone_Kid

Array "push" implementation using pushBack, alternative to BIS_fnc_arrayPush

KK_fnc_push = {
    _this select 0 pushBack (_this select 1);
    _this select 0
};

// Example
arr = [1,2,3];
[arr, 4] call KK_fnc_push; //both arr and return of function are now [1,2,3,4]
OOKexOo

Note that pushBack does not create a new object.

Therefore, if you edit an object that was pushed back to an array, it also affects the object in the array. e.g.

_first_squence = [1,2,3];
_second_squence = [5,4];

_first_squence pushBack _second_squence;
systemChat str _first_squence // prints [1,2,3,[5,4]]]

reverse _second_squence;
systemChat str _first_squence // prints [1,2,3,[4,5]]]

If you pushBack an array for instance, you can just copy it to generate a new object. e.g.

_first_squence pushBack +_second_squence;