{"name":"select","operator":null,"title":"select","type":"command","url":"https://community.bistudio.com/wiki/select","revid":377134,"updated":"2026-01-01T10:27:32Z","groups":["Arrays","Strings","Config"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Selects an element from an array, config entry from Config or substring from a string or a range from an array.","syntaxes":[{"syntax":"array select index","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array: Array of Anything"},{"name":"index","type":"Number","optional":false,"default":null,"description":"index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up.\n\nArma 3 v2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element.","types":["Number"],"since":null,"text":"index: Number - index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up.\n\nArma 3 v2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element."}],"returns":{"type":"Anything","types":["Anything"],"description":"a reference to the array element given by its index > [!IMPORTANT] > When the index equals the size of the array, there is no error for out of range selection and nil is returned - see #Example 8.","text":"Anything - a reference to the array element given by its index\n\n> [!IMPORTANT]\n> When the index equals the size of the array, there is no error for out of range selection and nil is returned - see #Example 8."},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"index","types":["Number"]}},{"syntax":"array select boolean","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array: Array of Anything"},{"name":"boolean","type":"Boolean","optional":false,"default":null,"description":"false selects the **first** element of the Array, true the **second** one","types":["Boolean"],"since":null,"text":"boolean: Boolean - false selects the **first** element of the Array, true the **second** one"}],"returns":{"type":"Anything","types":["Anything"],"description":"a reference to the array element","text":"Anything - a reference to the array element"},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"boolean","types":["Boolean"]}},{"syntax":"config select index","since":"arma1 1.00","effect":null,"exec":null,"params":[{"name":"config","type":"Config","optional":false,"default":null,"description":null,"types":["Config"],"since":null,"text":"config: Config"},{"name":"index","type":"Number","optional":false,"default":null,"description":"index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up","types":["Number"],"since":null,"text":"index: Number - index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up"}],"returns":{"type":"Config","types":["Config"],"description":null,"text":"Config"},"form":"binary","operator":null,"left":{"text":"config","types":["Config"]},"right":{"text":"index","types":["Number"]}},{"syntax":"string select [start, length]","since":"arma3 1.28","effect":null,"exec":null,"params":[{"name":"string","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"string: String"},{"name":"start","type":"Number","optional":false,"default":null,"description":"string position to start selection from. 0 denotes the first character of the string, 1 the second, etc. If passed number has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up","types":["Number"],"since":null,"text":"start: Number - string position to start selection from. 0 denotes the first character of the string, 1 the second, etc. If passed number has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up"},{"name":"length","type":"Number","optional":true,"default":"string's length","description":"number of characters to select","types":["Number"],"since":null,"text":"length: Number - (Optional, default *string*'s length) number of characters to select"}],"returns":{"type":null,"types":["String"],"description":null,"text":"String\n\n> [!NOTE]\n> Substring version of select operates with the ANSI charset; if Unicode support is desired, see forceUnicode."},"form":"binary","operator":null,"left":{"text":"string","types":["String"]},"right":{"text":"[start, length]","types":["Array"]}},{"syntax":"array select [start, count]","since":"arma3 1.32","effect":null,"exec":null,"params":[{"name":"array","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array: Array of Anything"},{"name":"start","type":"Number","optional":false,"default":null,"description":"array index to start selection from","types":["Number"],"since":null,"text":"start: Number - array index to start selection from"},{"name":"count","type":"Number","optional":true,"default":null,"description":"number of array elements to select. If the selected range exceeds source array boundaries, selection will be made up to the last element of the array.\n\n> [!NOTE]\n> Since v2.14 'count' is optional, if omitted the selection is made from *start* until the end of the array.","types":["Number"],"since":null,"text":"count: Number - (Optional after Arma 3 v2.14) number of array elements to select. If the selected range exceeds source array boundaries, selection will be made up to the last element of the array.\n\n> [!NOTE]\n> Since v2.14 'count' is optional, if omitted the selection is made from *start* until the end of the array."}],"returns":{"type":"Array","types":["Array"],"description":"a new array from selection","text":"Array - a new array from selection"},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"[start, count]","types":["Array"]}},{"syntax":"array select expression","since":"arma3 1.56","effect":null,"exec":null,"params":[{"name":"array","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array: Array of Anything"},{"name":"expression","type":"Code","optional":false,"default":null,"description":"expression that is expected to return Boolean or Nothing.\nIf true is returned, the original array value of currently tested element _x will be added to the output array","types":["Code"],"since":null,"text":"expression: Code - expression that is expected to return Boolean or Nothing.\nIf true is returned, the original array value of currently tested element _x will be added to the output array"}],"returns":{"type":"Array","types":["Array"],"description":"a new array of all elements from the original array that satisfied expression condition","text":"Array - a new array of all elements from the original array that satisfied expression condition"},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"expression","types":["Code"]}}],"examples":[{"text":"```sqf\n[\"a\", \"b\", \"c\", \"d\"] select 2;    // result is \"c\"\nposition player select 2;        // result is Z coordinate of player position\n```","code":["[\"a\", \"b\", \"c\", \"d\"] select 2;\t// result is \"c\"\nposition player select 2;\t\t// result is Z coordinate of player position"]},{"text":"```sqf\n[\"\", currentWeapon player] select alive player; // if player is dead, \"\" is selected\n```","code":["[\"\", currentWeapon player] select alive player; // if player is dead, \"\" is selected"]},{"text":"```sqf\n(configFile >> \"cfgVehicles\" >> typeOf vehicle player >> \"Turrets\") select 0 >> \"gunnerAction\";\n```","code":["(configFile >> \"cfgVehicles\" >> typeOf vehicle player >> \"Turrets\") select 0 >> \"gunnerAction\";"]},{"text":"```sqf\nhint str (\"japa is the man!\" select [8]);        // the man!\nhint str (\"japa is the man!\" select [0, 7]);    // japa is\n```","code":["hint str (\"japa is the man!\" select [8]);\t\t// the man!\nhint str (\"japa is the man!\" select [0, 7]);\t// japa is"]},{"text":"```sqf\nhint str ([1,2,3,4,5,6] select [1, 4]); // [2,3,4,5]\n```","code":["hint str ([1,2,3,4,5,6] select [1, 4]); // [2,3,4,5]"]},{"text":"```sqf\n_even = [1,2,3,4,5,6,7,8,9,0] select { _x % 2 == 0 }; // returns [2, 4, 6, 8, 0]\n```","code":["_even = [1,2,3,4,5,6,7,8,9,0] select { _x % 2 == 0 }; // returns [2, 4, 6, 8, 0]"]},{"text":"JavaScript endsWith() alternative:\n\n```sqf\nprivate _fnc_endsWith = \n{\n    params [\"_string\", \"_endswith\"];\n    _string select [count _string - count _endswith] isEqualTo _endswith\n};\n\n[\"Arma 3\", \"3\"] call _fnc_endsWith; // true\n[\"Arma 3\", \"4\"] call _fnc_endsWith; // false\n```","code":["private _fnc_endsWith = \n{\n\tparams [\"_string\", \"_endswith\"];\n\t_string select [count _string - count _endswith] isEqualTo _endswith\n};\n\n[\"Arma 3\", \"3\"] call _fnc_endsWith; // true\n[\"Arma 3\", \"4\"] call _fnc_endsWith; // false"]},{"text":"select index traps:\n\n```sqf\nprivate _array = [\"a\", \"b\", \"c\", \"d\"];\n_array select 0; // \"a\"\n_array select 3; // \"d\"\n_array select 4; // nil - no error shown\n_array select 5; // error\n\n// can sometimes be useful\nprivate _firstEnemyNearMe = units opfor select { player distance _x < 10 } select 0; // nil if no enemies nearby\nif (isNil \"_firstEnemyNearMe\") exitWith { systemChat \"no enemy found\" };\nsystemChat format [\"enemy found: %1\", name _firstEnemyNearMe];\n\n// get the last element properly\n_array select (count _array);        // wrong - nil is returned\n_array select (count _array - 1);    // correct - \"d\" is returned\n```","code":["private _array = [\"a\", \"b\", \"c\", \"d\"];\n_array select 0; // \"a\"\n_array select 3; // \"d\"\n_array select 4; // nil - no error shown\n_array select 5; // error\n\n// can sometimes be useful\nprivate _firstEnemyNearMe = units opfor select { player distance _x < 10 } select 0; // nil if no enemies nearby\nif (isNil \"_firstEnemyNearMe\") exitWith { systemChat \"no enemy found\" };\nsystemChat format [\"enemy found: %1\", name _firstEnemyNearMe];\n\n// get the last element properly\n_array select (count _array);\t\t// wrong - nil is returned\n_array select (count _array - 1);\t// correct - \"d\" is returned"]},{"text":"> [!NOTE]\n> **Arma 3:** Since Arma 3 v2.12 `-1` can be used to select the last element of an array.\n\n```sqf\nprivate _array = [1, 2, 3, 4, 5];\nhint str (_array select -1); // 5\n```","code":["private _array = [1, 2, 3, 4, 5];\nhint str (_array select -1); // 5"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["a hash b","selectRandom","selectRandomWeighted","set","resize","reverse","in","find","findIf","toArray","toString","forEach","count","deleteAt","deleteRange","append","sort","param","params","splitString","joinString","pushBack","pushBackUnique","apply","forceUnicode"],"notes":[{"user":"General Barron","date":"2009-03-03T02:02:00Z","text":"When combined with the count command, this can be used to read all entries out of a config; even when you don't know exactly how many entries there will be.\nSee the notes under count for more info."},{"user":"Killzone_Kid","date":"2013-09-28T00:53:00Z","text":"Rounding of fractions with select is not the same as when you use round command:\n\n```sqf\n_roundThis = 0.5;\nhint str ([0,1] select _roundThis);            // 0\nhint str ([0,1] select round _roundThis);    // 1\n```"},{"user":"Pierre MGI","date":"2016-07-14T04:18:00Z","text":"You can substract array from array using select:\n\n```sqf\n_array = [[1], [2], [3]];\n_sub = [2];\n_array - _sub; // [[1], [2], [3]]\n_array select { !(_x isEqualTo _sub) }; // [[1], [3]]\n[[1],[2],[2],[2],[2],[3]] select { !(_x isEqualTo _sub) }; // [[1], [3]]\n```"},{"user":"Commy2","date":"2016-11-12T22:36:00Z","text":"It is not safe to escape the code block of alternative syntax #5 with exitWith, breakOut etc:\n\n```sqf\nx3 = [1,2,3,4,5] select {\n    if (_x == 3) exitWith\n    {\n        false;\n    };\n    true\n};\n// could be expected to be: x3 = [1,2,4,5]\n// actual result: x3 = false\n```"},{"user":"Igneous01","date":"2017-02-14T16:26:00Z","text":"#Syntax 5 is the equivalent of passing in a predicate that returns a boolean. In SQF, a piece of code will always return what the last executed command returned.\n\n```sqf\nmyAliveUnits = allUnits select { alive _x };    // alive returns a boolean, the last statement run was alive _x,\n                                                // therefore this piece of code will return a true/false to the select command\nmyEastGroups = allGroups select { side _x == east };                    // returns all east groups\nmy4ManGroups = allGroups select { count units _x == 4 };                // returns all groups that have 4 men in them\nunitsThatDetectedMe = allUnits select { _x knowsAbout player > 0.1 };    // returns a list of units that have detected the player\n```"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Command Group: Config","Command Group: Strings","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}