{"name":"set","title":"set","type":"command","url":"https://community.bistudio.com/wiki/set","revid":377132,"updated":"2026-01-01T10:26:06Z","groups":["Arrays","HashMap"],"status":"ok","games":{"ofp":"1.75","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.75","arma3_since":"0.50","description":"Changes the element at the given zero-based index of the array.\n\n> [!NOTE]\n> If the index is out of bounds, the array will resize to incorporate the index as its last value, padding with nil as necessary (see Example 4).","syntaxes":[{"syntax":"array set [index, value]","params":[{"name":"array","type":"Array of Anything","type_expr":"Array<Anything>"},{"name":"index","type":"Number","description":"0-based array index. Arma 3 v2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element.","type_expr":"Number"},{"name":"value","type":"Anything","type_expr":"Anything"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"array"},"right":{"text":"[index, value]"}},{"syntax":"hashMap set [key, value, insertOnly]","since":"arma3 2.02","params":[{"name":"hashMap","type":"HashMap","type_expr":"HashMap"},{"name":"key","type":"HashMapKey","type_expr":"HashMapKey"},{"name":"value","type":"Anything","type_expr":"Anything"},{"name":"insertOnly","type":"Boolean","optional":true,"default":"false","description":"if set to true, set the value only if the key does not exist already","type_expr":"Boolean","since":"arma3 2.08","text":"insertOnly: Boolean - (Optional, default false) if set to true, set the value only if the key does not exist already"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"false if the key is new to the hashmap, true if a value got overwritten"},"form":"binary","left":{"text":"hashMap"},"right":{"text":"[key, value, insertOnly]"}}],"examples":[{"code":["_arrayOne set [0, \"Hello\"];"]},{"text":"Append \"Bye\" as last element to `_arrayTwo`:\n\n```sqf\n_arrayTwo set [count _arrayTwo, \"Bye\"];\n```","code":["_arrayTwo set [count _arrayTwo, \"Bye\"];"]},{"text":"Replace the last element of `_arrayThree` with 23:\n\n```sqf\n_arrayThree set [(count _arrayThree) - 1, 23];\n```","code":["_arrayThree set [(count _arrayThree) - 1, 23];"]},{"text":"Using set with an index that is out of bounds:\n\n```sqf\nprivate _array = [\"A\"];\n_array set [2, \"C\"]; // _array is now [\"A\", nil, \"C\"]\n_array set [1, \"B\"]; // _array is now [\"A\", \"B\", \"C\"]\n```","code":["private _array = [\"A\"];\n_array set [2, \"C\"]; // _array is now [\"A\", nil, \"C\"]\n_array set [1, \"B\"]; // _array is now [\"A\", \"B\", \"C\"]"]},{"code":["private _myHashMap = createHashMap;\n_myHashMap set [\"key\", \"value1\", true]; // \"key\" value is set to \"value1\"\n_myHashMap set [\"key\", \"value2\", true]; // \"key\" value is still \"value1\" as \"key\" already exists in the hashmap"]}],"see_also":["resize","reverse","select","deleteAt","deleteRange"]}