findIf: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Some wiki formatting) |
Lou Montana (talk | contribs) m (Text replacement - "{{HashLink" to "{{Link") |
||
Line 8: | Line 8: | ||
|descr= Searches for an element within array for which the code evaluates to true. Returns the zero-based index on success or -1 if not found.<br> | |descr= Searches for an element within array for which the code evaluates to true. Returns the zero-based index on success or -1 if not found.<br> | ||
Code on the right side of the command is evaluated for each element of the array, processed element can be referenced in code as [[Magic Variables#x|_x]]. | Code on the right side of the command is evaluated for each element of the array, processed element can be referenced in code as [[Magic Variables#x|_x]]. | ||
{{Feature|informative|[[findIf]] terminates as soon as it finds an element that fulfills the condition, thus it is more efficient than [[count]] in scenarios where a check for presence / absence of at least one element should be done (See {{ | {{Feature|informative|[[findIf]] terminates as soon as it finds an element that fulfills the condition, thus it is more efficient than [[count]] in scenarios where a check for presence / absence of at least one element should be done (See {{Link|#Example 2}}).}} | ||
|s1= array [[findIf]] code | |s1= array [[findIf]] code |
Revision as of 17:44, 4 January 2023
Description
- Description:
- Searches for an element within array for which the code evaluates to true. Returns the zero-based index on success or -1 if not found.
Code on the right side of the command is evaluated for each element of the array, processed element can be referenced in code as _x. - Groups:
- Arrays
Syntax
- Syntax:
- array findIf code
- Parameters:
- array: Array - array to search in
- code: Code - code defining an element to find, processed element can be referenced within the code as _x
- Return Value:
- Number - Zero-based position of the first array element for which the code evaluate to true, -1 if not found
Examples
- Example 1:
- Example 2:
Additional Information
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