# deleteAt ## Category Array ## Arity **Binary** — ` deleteAt `. ``` deleteAt ``` ## Description Removes the element at the given zero-based index from the array. Returns the deleted value. If the index is out of range, returns `nil` and the array is unchanged. ## How It Works Checks bounds. If valid, retrieves the element at `index`, removes it from the list (shifting subsequent elements left), and returns the retrieved value. O(n) due to shift. ## Usage ### Remove by index ```sqf _arr = ["a", "b", "c", "d"]; _removed = _arr deleteAt 1; // returns "b", _arr is ["a","c","d"] ``` ### Pop from front (queue dequeue) ```sqf _queue = [1, 2, 3, 4]; _next = _queue deleteAt 0; // returns 1, _queue is [2,3,4] ``` ### Pop from back ```sqf _stack = [1, 2, 3]; _top = _stack deleteAt (count _stack - 1); // returns 3 ``` ### Safe delete (guard out-of-range) ```sqf if (_index >= 0 && _index < count _arr) then { _val = _arr deleteAt _index; }; ``` ### Remove matching element ```sqf _removeByValue = { params ["_arr", "_val"]; _idx = _arr find _val; if (_idx != -1) then { _arr deleteAt _idx }; }; ``` ## Thread Safety **Not thread-safe**. Array must belong to the current scheduler. ## See Also - [deleteRange](deleteRange.md) — remove multiple elements - [pushBack](pushBack.md) — append element - [select](select.md) — element access - [find](find.md) — find element index - [resize](resize.md) — change array size