append: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "+" to "+")
 
(48 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma3 |= Game name
|game1= arma3
|version1= 1.40


|1.40|= Game version
|gr1= Arrays


____________________________________________________________________________________________
|descr= Appends array2 to the back of array1 modifying array1. See [[insert]] for an "appendUnique" equivalent.
{{Feature|informative|[[append]] does not return array, it modifies the existing array. If you need to return a copy, use "[[+]]": <sqf>array3 = array1 + array2;</sqf>}}


| Appends array2 to the back of array1 modifying array1. |= Description
|s1= array1 [[append]] array2
____________________________________________________________________________________________


| array1 '''append''' array2|= Syntax
|p1= array1: [[Array]]


|p1= array1: [[Array]] |= Parameter 1
|p2= array2: [[Array]]


|p2= array2: [[Array]] |= Parameter 2
|r1= [[Nothing]]


| [[Nothing]] |= Return value
|x1= <sqf>
____________________________________________________________________________________________
_arr = [1,2,3];
 
_arr append [4,5,6];
|x1= <code>_arr = [1,2,3];
hint str _arr; // [1,2,3,4,5,6]
_arr [[append]] [4,5,6];
</sqf>
[[hint]] [[str]] _arr; //[1,2,3,4,5,6]</code> |= Example 1
 
____________________________________________________________________________________________
 
| [[set]], [[pushBack]], [[resize]], [[reverse]], [[count]], [[find]], [[in]], [[forEach]], [[deleteAt]], [[deleteRange]], [[sort]], [[BIS_fnc_arrayPushStack]], [[BIS_fnc_arrayPush]] |= See also


|seealso= [[set]] [[pushBack]] [[pushBackUnique]] [[insert]] [[+]] [[apply]] [[select]] [[resize]] [[reverse]] [[count]] [[deleteAt]] [[deleteRange]]
}}
}}


[[Category:Scripting_Commands_Arma_3]]
{{Note
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
|user= Heeeere's Johnny!
 
|timestamp= 20150309004100
<!-- CONTINUE Notes -->
|text= <sqf>_array1 append _array2;</sqf>
<dl class="command_description">
is roughly 1.2&times; faster (depending on array size) than
<dd class="notedate">Posted on March 9, 2015 - 00:41 (UTC)</dd>
<sqf>_array1 = _array1 + _array2</sqf>
<dt class="note">[[User:Heeeere's Johnny!|Heeeere's Johnny!]]</dt>
(Averaged over 10.000 iterations with two identical arrays containing the numbers 0 through 9)<br>
<dd class="note">
<code>_array1 [[append]] _array2</code> is roughly 1.2x faster (depending on array size) than <code>_array1 <nowiki>=</nowiki> _array1 + _array2</code>(Averaged over 10.000 iterations with two identical arrays containing the numbers 0 through 9)<br />


The larger the arrays to append, the faster [[append]] is as it does not create a new array, which happens with array addition.
The larger the arrays to append, the faster [[append]] is as it does not create a new array, which happens with array addition.
</dd>
}}
</dl>
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Killzone_Kid
<dd class="notedate">Posted on May 21, 2015 - 10:27 (UTC)</dd>
|timestamp= 20150521102700
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
|text= Array "unshift" implementation using [[append]], a faster alternative to [[BIS_fnc_arrayUnShift]]:
<dd class="note">
<sqf>
Array "unshift" implementation using [[append]], a faster alternative to [[BIS_fnc_arrayUnShift]]:
KK_fnc_unshift = {
<code>KK_fnc_unshift <nowiki>=</nowiki> {
private ["_arr", "_tmp"];
[[private]] ["_arr", "_tmp"];
_arr = _this select 0;
_arr <nowiki>=</nowiki> _this [[select]] 0;
_tmp = [_this select 1];
_tmp <nowiki>=</nowiki> [_this [[select]] 1];
_tmp append _arr;
_tmp [[append]] _arr;
_arr resize 0;
_arr [[resize]] 0;
_arr append _tmp;
_arr [[append]] _tmp;
_arr
_arr
};
};


// Example
// Example
arr <nowiki>=</nowiki> [1,2,3];
arr = [1,2,3];
[arr, 0] [[call]] KK_fnc_unshift; //both arr and return of function are [0,1,2,3]
[arr, 0] call KK_fnc_unshift; // both arr and return of function are [0,1,2,3]
</code>
</sqf>
</dd>
}}
</dl>
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Killzone_Kid
<dd class="notedate">Posted on May 21, 2015 - 15:21 (UTC)</dd>
|timestamp= 20150521152100
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
|text= Array "insert" implementation using [[append]], much faster alternative to [[BIS_fnc_arrayInsert]]:
<dd class="note">
<sqf>
Array "insert" implementation using [[append]], much faster alternative to [[BIS_fnc_arrayInsert]]:
KK_fnc_insert = {
<code>KK_fnc_insert <nowiki>=</nowiki> {
private ["_arr", "_i", "_res"];
[[private]] ["_arr", "_i", "_res"];
_arr = _this select 0;
_arr <nowiki>=</nowiki> _this [[select]] 0;
_i = _this select 2;
_i <nowiki>=</nowiki> _this [[select]] 2;
_res = [];
_res <nowiki>=</nowiki> [];
_res append (_arr select [0, _i]);
_res [[append]] (_arr [[select]] [0, _i]);
_res append (_this select 1);
_res [[append]] (_this [[select]] 1);
_res append (_arr select [_i, count _arr - _i]);
_res [[append]] (_arr [[select]] [_i, [[count]] _arr - _i]);
_res;
_res
};
};


// Example
// Example
arr <nowiki>=</nowiki> [1,2,3,4];
arr = [1,2,3,4];
[arr, ["a","b"], 2] [[call]] KK_fnc_insert; //[1,2,"a","b",3,4]</code>
[arr, ["a","b"], 2] call KK_fnc_insert; // [1,2,"a","b",3,4]
</dd>
</sqf>
</dl>
}}
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Killzone_Kid
<dd class="notedate">Posted on May 21, 2015 - 15:52 (UTC)</dd>
|timestamp= 20150521155200
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
|text= A faster alternative to [[BIS_fnc_arrayPushStack]] using [[append]]:
<dd class="note">
<sqf>
A faster alternative to [[BIS_fnc_arrayPushStack]] using [[append]]:
KK_fnc_pushStack = {
<code>KK_fnc_pushStack <nowiki>=</nowiki> {
_this select 0 append (_this select 1);
_this [[select]] 0 [[append]] (_this [[select]] 1);
_this select 0
_this [[select]] 0
};
};


// Example
// Example
arr <nowiki>=</nowiki> [1,2,3];
arr = [1,2,3];
[arr,[4,5,6]] [[call]] KK_fnc_pushStack; //both arr and function return are [1,2,3,4,5,6]</code>
[arr, [4,5,6]] call KK_fnc_pushStack; // both arr and function return are [1,2,3,4,5,6]
</dd>
</sqf>
</dl>
}}
<!-- DISCONTINUE Notes -->

Latest revision as of 19:52, 9 August 2022

Hover & click on the images for description

Description

Description:
Appends array2 to the back of array1 modifying array1. See insert for an "appendUnique" equivalent.
append does not return array, it modifies the existing array. If you need to return a copy, use "+":
array3 = array1 + array2;
Groups:
Arrays

Syntax

Syntax:
array1 append array2
Parameters:
array1: Array
array2: Array
Return Value:
Nothing

Examples

Example 1:
_arr = [1,2,3]; _arr append [4,5,6]; hint str _arr; // [1,2,3,4,5,6]

Additional Information

See also:
set pushBack pushBackUnique insert + apply select resize reverse count deleteAt deleteRange

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Heeeere's Johnny! - c
Posted on Mar 09, 2015 - 00:41 (UTC)
_array1 append _array2;
is roughly 1.2× faster (depending on array size) than
_array1 = _array1 + _array2
(Averaged over 10.000 iterations with two identical arrays containing the numbers 0 through 9)
The larger the arrays to append, the faster append is as it does not create a new array, which happens with array addition.
Killzone_Kid - c
Posted on May 21, 2015 - 10:27 (UTC)
Array "unshift" implementation using append, a faster alternative to BIS_fnc_arrayUnShift:
KK_fnc_unshift = { private ["_arr", "_tmp"]; _arr = _this select 0; _tmp = [_this select 1]; _tmp append _arr; _arr resize 0; _arr append _tmp; _arr }; // Example arr = [1,2,3]; [arr, 0] call KK_fnc_unshift; // both arr and return of function are [0,1,2,3]
Killzone_Kid - c
Posted on May 21, 2015 - 15:21 (UTC)
Array "insert" implementation using append, much faster alternative to BIS_fnc_arrayInsert:
KK_fnc_insert = { private ["_arr", "_i", "_res"]; _arr = _this select 0; _i = _this select 2; _res = []; _res append (_arr select [0, _i]); _res append (_this select 1); _res append (_arr select [_i, count _arr - _i]); _res; }; // Example arr = [1,2,3,4]; [arr, ["a","b"], 2] call KK_fnc_insert; // [1,2,"a","b",3,4]
Killzone_Kid - c
Posted on May 21, 2015 - 15:52 (UTC)
A faster alternative to BIS_fnc_arrayPushStack using append:
KK_fnc_pushStack = { _this select 0 append (_this select 1); _this select 0 }; // Example arr = [1,2,3]; [arr, [4,5,6]] call KK_fnc_pushStack; // both arr and function return are [1,2,3,4,5,6]