apply: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Command " to "{{RV|type=command ")
(removed old functions from see also)
Line 25: Line 25:
|x4= <code>[0,1,2,3,4] [[apply]] {[[str]] _x}; {{cc|Returns ["0","1","2","3","4"]}}</code>
|x4= <code>[0,1,2,3,4] [[apply]] {[[str]] _x}; {{cc|Returns ["0","1","2","3","4"]}}</code>


| [[set]], [[resize]], [[pushBack]], [[pushBackUnique]], [[select]], [[reverse]], [[count]], [[find]], [[in]], [[forEach]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[arrayIntersect]], [[BIS_fnc_arrayPushStack]], [[BIS_fnc_arrayPush]]
| [[set]], [[resize]], [[pushBack]], [[pushBackUnique]], [[select]], [[reverse]], [[count]], [[find]], [[in]], [[forEach]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[arrayIntersect]]
}}
}}



Revision as of 15:02, 26 January 2021

Hover & click on the images for description

Description

Description:
Description needed
Groups:
Arrays

Syntax

Syntax:
Syntax needed
Parameters:
array: Array - array of Anything
code: Code - code to be executed on each element of the array. Current element value is stored in variable _x
Return Value:
Return value needed

Examples

Example 1:
_arr = [1,2,3,4,5,6,7,8,9,0] apply {[1,0] select (_x % 2 == 0)}; //[1,0,1,0,1,0,1,0,1,0]
Example 2:
_arr = [1,2,3,4,5,6,7,8,9,0] apply {_x ^ _x}; //[1,4,27,256,3125,46656,823543,16777216,387420480,1]
Example 3:
_arr1 = []; _arr1 resize 20; _arr2 = _arr1 apply {0}; //[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Example 4:
[0,1,2,3,4] apply {str _x}; // Returns ["0","1","2","3","4"]

Additional Information

See also:
See also needed

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
Posted on February 18, 2016 - 11:03 (UTC)
Fusselwurm
(to anyone else wondering, I took a minute to get it): This is Array.map() in JavaScript
Posted on February 11, 2018 - 23:02 (UTC)
Lou Montana
if performance really is an issue, apply seems to be (very) slightly faster than forEach (by more or less one percent, 0.7-1.5% in my tests to be precise).