{"name":"deleteAt","operator":null,"title":"deleteAt","type":"command","url":"https://community.bistudio.com/wiki/deleteAt","revid":378389,"updated":"2026-04-04T07:34:56Z","groups":["Arrays","HashMap"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.32"}],"since":{"game":"arma3","name":"Arma 3","version":"1.32"},"arma3_since":"1.32","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Removes array element at the given index and returns removed element (modifies the original array, just like resize or set).\n\n> [!NOTE]\n> For the main Array variant, if the index is a negative Number, no error will appear, making it ideal for using with find (see #Example 2) or findIf (see #Example 3).","syntaxes":[{"syntax":"array deleteAt 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":"see the note in description","types":["Number"],"since":null,"text":"index: Number - see the note in description"}],"returns":{"type":"Anything or Nothing","types":["Anything","Nothing"],"description":"returns the deleted element if one existed","text":"Anything or Nothing - returns the deleted element if one existed"},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"index","types":["Number"]}},{"syntax":"hashMap deleteAt key","since":"arma3 2.02","effect":null,"exec":null,"params":[{"name":"hashMap","type":"HashMap","optional":false,"default":null,"description":null,"types":["HashMap"],"since":null,"text":"hashMap: HashMap"},{"name":"key","type":"HashMapKey","optional":false,"default":null,"description":null,"types":["HashMapKey"],"since":null,"text":"key: HashMapKey"}],"returns":{"type":"Anything","types":["Anything"],"description":null,"text":"Anything"},"form":"binary","operator":null,"left":{"text":"hashMap","types":["HashMap"]},"right":{"text":"key","types":["HashMapKey"]}},{"syntax":"array deleteAt indexes","since":"arma3 2.18","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":"indexes","type":"Array of Numbers","optional":false,"default":null,"description":"multiple indexes, negative indexes are supported and would remove elements counting from the end of array (see #Example 4).","types":["Array","Number"],"since":null,"text":"indexes: Array of Numbers - multiple indexes, negative indexes are supported and would remove elements counting from the end of array (see #Example 4)."}],"returns":{"type":"Array of Anything","types":["Array","Anything"],"description":"deleted elements in order of user supplied indexes","text":"Array of Anything - deleted elements in order of user supplied indexes"},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"indexes","types":["Array","Number"]}}],"examples":[{"text":"```sqf\n_arr = [1,2,3];\n_rem = _arr deleteAt 1;\nhint str [_rem, _arr]; // [2, [1, 3]]\n```","code":["_arr = [1,2,3];\n_rem = _arr deleteAt 1;\nhint str [_rem, _arr]; // [2, [1, 3]]"]},{"text":"```sqf\n_arr = [1,2,3];\n_arr deleteAt (_arr find 0); // non existent item\nhint str _arr; // [1,2,3]\n_arr deleteAt (_arr find 2); // existent item\nhint str _arr; // [1,3]\n```","code":["_arr = [1,2,3];\n_arr deleteAt (_arr find 0); // non existent item\nhint str _arr; // [1,2,3]\n_arr deleteAt (_arr find 2); // existent item\nhint str _arr; // [1,3]"]},{"text":"```sqf\n_arr = [1,2,3];\n_arr deleteAt (_arr findIf {(_x % 5) == 0}); // Remove first number that's divisible by 5\nhint str _arr; // [1,2,3]\n_arr deleteAt (_arr findIf {(_x % 2) == 0}); // Remove first number that's divisible by 2\nhint str _arr; // [1,3]\n```","code":["_arr = [1,2,3];\n_arr deleteAt (_arr findIf {(_x % 5) == 0}); // Remove first number that's divisible by 5\nhint str _arr; // [1,2,3]\n_arr deleteAt (_arr findIf {(_x % 2) == 0}); // Remove first number that's divisible by 2\nhint str _arr; // [1,3]"]},{"text":"```sqf\n_arr = [1,2,3,4];\n_res = _arr deleteAt [-1, 0]; // Remove the last and the first array element\nsystemchat str [_res, _arr]; // [[4,1],[2,3]]\n```","code":["_arr = [1,2,3,4];\n_res = _arr deleteAt [-1, 0]; // Remove the last and the first array element\nsystemchat str [_res, _arr]; // [[4,1],[2,3]]"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["deleteRange","set","resize","select","in","find","findIf","toArray","toString","forEach","count","pushBack","pushBackUnique","apply","append","sort","param","params","arrayIntersect","splitString","joinString"],"notes":[{"user":"Heeeere's Johnny!","date":"2014-10-15T16:55:00Z","text":"```sqf\n_array deleteAt 0;\n```\n\n is almost 60x faster than \n\n```sqf\n_array = _array - [_array select 0]\n```\n\n (Tested with an array of 10.000 strings, iterating through it using a for-from-to-do loop)"},{"user":"Highhead","date":"2016-03-04T15:58:00Z","text":"Deleting from an array with foreach and _foreachIndex variable is tricky.\nThe array is being altered, the _foreachIndex won't keep up and other elements in the array will be skipped and in worst case not being deleted.\nIf you delete elements from an array in descending order (using while or for) it will work."},{"user":"Igneous01","date":"2017-02-09T22:45:00Z","text":"To expand on Highheads comment above - this is because forEach implements iterators to traverse a collection, which are read only by definition.\nThe variable _x is an iterator that points to the current item in the collection. Trying to alter _x will have no effect.\n\n```sqf\nprivate _array = [1,2,3,4,5,6,7,8];\n{ _x = 2; } forEach _array\n// _array is still [1,2,3,4,5,6,7,8]\n```\n\nWhen trying to use deleteAt inside forEach, the behaviour would be undefined as you are invalidating the iterator reference, and it will not know how to traverse to the next element.\nIn short, only use forEach when reading data from an array.\nFor more info about iterators, see C++ Iterators."},{"user":"Freghar","date":"2021-02-01T18:06:00Z","text":"As you would expect from a simple array implementation,\n\n```sqf\narray deleteAt (count array - 1);\n```\n\nis virtually zero cost (0.0005ms on an array of 1000000 elements), while\n\n```sqf\narray deleteAt 0;\n```\n\nis very performance heavy (0.7ms on the same huge array)."}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Command Group: HashMap","Introduced with Arma 3 version 1.32","Scripting Commands"]}