{"name":"findIf","operator":null,"title":"findIf","type":"command","url":"https://community.bistudio.com/wiki/findIf","revid":376518,"updated":"2025-10-22T23:13:13Z","groups":["Arrays"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.82"}],"since":{"game":"arma3","name":"Arma 3","version":"1.82"},"arma3_since":"1.82","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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.\n\nCode on the right side of the command is evaluated for each element of the array, processed element can be referenced in code as _x.\n\n> [!NOTE]\n> 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 #Example 2).","syntaxes":[{"syntax":"array findIf code","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array","optional":false,"default":null,"description":"array to search in","types":["Array"],"since":null,"text":"array: Array - array to search in"},{"name":"code","type":"Code","optional":false,"default":null,"description":"code defining an element to find, processed element can be referenced within the code as _x","types":["Code"],"since":null,"text":"code: Code - code defining an element to find, processed element can be referenced within the code as _x"}],"returns":{"type":"Number","types":["Number"],"description":"zero-based position of the first array element for which the code evaluate to true, -1 if not found","text":"Number - zero-based position of the first array element for which the code evaluate to true, -1 if not found"},"form":"binary","operator":null,"left":{"text":"array","types":["Array"]},"right":{"text":"code","types":["Code"]}}],"examples":[{"text":"```sqf\nprivate _firstDead = [unit1, unit2, unit3] findIf { not alive _x }; // return index of the first dead unit\n```","code":["private _firstDead = [unit1, unit2, unit3] findIf { not alive _x }; // return index of the first dead unit"]},{"text":"```sqf\n// two ways how to 'wait for all units to be dead':\nwaitUntil { [unit1, unit2, unit3] findIf { alive _x } == -1 };    // fast, terminates as soon as it finds a living unit\nwaitUntil { { alive _x } count [unit1, unit2, unit3] == 0 };    // slow, always goes through all array elements\n```","code":["// two ways how to 'wait for all units to be dead':\nwaitUntil { [unit1, unit2, unit3] findIf { alive _x } == -1 };\t// fast, terminates as soon as it finds a living unit\nwaitUntil { { alive _x } count [unit1, unit2, unit3] == 0 };\t// slow, always goes through all array elements"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["find","count"],"notes":[],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Introduced with Arma 3 version 1.82","Scripting Commands"]}