apply: Difference between revisions
BrettMayson (talk | contribs) mNo edit summary |
BrettMayson (talk | contribs) mNo edit summary |
||
| Line 15: | Line 15: | ||
|p2= code: [[Code]] - code to be executed on each element of the array. The current element value is stored in the magic variable [[Magic Variables#x|_x]]. | |p2= code: [[Code]] - code to be executed on each element of the array. The current element value is stored in the magic variable [[Magic Variables#x|_x]]. | ||
|r1= [[Array]] - resulting array | |r1= [[Array]] of [[Anything]] - resulting array | ||
|s2= hashmap [[apply]] code | |s2= hashmap [[apply]] code | ||
| Line 25: | Line 25: | ||
|p22= code: [[Code]] - code to be executed on each key-value pair of the hashmap. The current key is stored in the magic variable [[Magic Variables#x|_x]], the corresponding value is stored in [[Magic Variables#y|_y]]. | |p22= code: [[Code]] - code to be executed on each key-value pair of the hashmap. The current key is stored in the magic variable [[Magic Variables#x|_x]], the corresponding value is stored in [[Magic Variables#y|_y]]. | ||
|r2= [[Array]] - resulting array | |r2= [[Array]] of [[Anything]] - resulting array | ||
|x1= <sqf>private _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]</sqf> | |x1= <sqf>private _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]</sqf> | ||
Latest revision as of 05:33, 3 January 2026
Description
- Description:
- Applies the given code to each element of the given data structure and collects the results in an array.
- Groups:
- ArraysHashMap
Syntax
- Syntax:
- array apply code
- Parameters:
- array: Array of Anything
- code: Code - code to be executed on each element of the array. The current element value is stored in the magic variable _x.
- Return Value:
- Array of Anything - resulting array
Alternative Syntax
- Syntax:
- hashmap apply code
- Parameters:
- hashmap: HashMap
- code: Code - code to be executed on each key-value pair of the hashmap. The current key is stored in the magic variable _x, the corresponding value is stored in _y.
- Return Value:
- Array of Anything - resulting array
Examples
- Example 1:
- Example 2:
- Example 3:
- Example 4:
- Example 5:
Additional Information
- See also:
- set resize pushBack pushBackUnique select reverse count find in forEach deleteAt deleteRange append sort arrayIntersect
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord.
Only post proven facts here! Add Note
- Posted on Feb 18, 2016 - 11:03 (UTC)
- (to anyone else wondering, I took a minute to get it) this is Array.map() in JavaScript