Skip to content

deleteAt

ffredyk edited this page Jul 23, 2026 · 1 revision

deleteAt

Category

Array

Arity

Binary<array> deleteAt <index>.

<array> deleteAt <number>

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

_arr = ["a", "b", "c", "d"];
_removed = _arr deleteAt 1;    // returns "b", _arr is ["a","c","d"]

Pop from front (queue dequeue)

_queue = [1, 2, 3, 4];
_next = _queue deleteAt 0;     // returns 1, _queue is [2,3,4]

Pop from back

_stack = [1, 2, 3];
_top = _stack deleteAt (count _stack - 1);  // returns 3

Safe delete (guard out-of-range)

if (_index >= 0 && _index < count _arr) then {
    _val = _arr deleteAt _index;
};

Remove matching element

_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

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally