---
name: "deleteAt"
type: command
status: ok
groups: ["Arrays", "HashMap"]
arma3_since: "1.32"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/deleteAt
revid: 378389
updated: 2026-04-04T07:34:56Z
---

# deleteAt

*Command · Arrays, HashMap · Arma 3 v1.32*

## Description

Removes array element at the given index and returns removed element (modifies the original array, just like [resize](../commands/resize.md) or [set](../commands/set.md)).

> [!NOTE]
> For the main [Array](../topics/Array.md) variant, if the index is a negative [Number](../topics/Number.md), no error will appear, making it ideal for using with [find](../commands/find.md) (see [#Example 2](../commands/deleteAt.md#example-2)) or [findIf](../commands/findIf.md) (see [#Example 3](../commands/deleteAt.md#example-3)).

## Syntax

### Syntax 1

```sqf
array deleteAt index
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `index`: [Number](../topics/Number.md) - see the note in description

**Returns:** [Anything](../topics/Anything.md) or [Nothing](../topics/Nothing.md) - returns the deleted element if one existed

### Syntax 2

*since arma3 2.02*

```sqf
hashMap deleteAt key
```

**Parameters:**

- `hashMap`: [HashMap](../topics/HashMap.md)
- `key`: [HashMapKey](../topics/HashMapKey.md)

**Returns:** [Anything](../topics/Anything.md)

### Syntax 3

*since arma3 2.18*

```sqf
array deleteAt indexes
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `indexes`: [Array](../topics/Array.md) of [Number](../topics/Number.md)s - multiple indexes, negative indexes are supported and would remove elements counting from the end of array (see [#Example 4](../commands/deleteAt.md#example-4)).

**Returns:** [Array](../topics/Array.md) of [Anything](../topics/Anything.md) - deleted elements in order of user supplied indexes

## Examples

### Example 1

```sqf
_arr = [1,2,3];
_rem = _arr deleteAt 1;
hint str [_rem, _arr]; // [2, [1, 3]]
```

### Example 2

```sqf
_arr = [1,2,3];
_arr deleteAt (_arr find 0); // non existent item
hint str _arr; // [1,2,3]
_arr deleteAt (_arr find 2); // existent item
hint str _arr; // [1,3]
```

### Example 3

```sqf
_arr = [1,2,3];
_arr deleteAt (_arr findIf {(_x % 5) == 0}); // Remove first number that's divisible by 5
hint str _arr; // [1,2,3]
_arr deleteAt (_arr findIf {(_x % 2) == 0}); // Remove first number that's divisible by 2
hint str _arr; // [1,3]
```

### Example 4

```sqf
_arr = [1,2,3,4];
_res = _arr deleteAt [-1, 0]; // Remove the last and the first array element
systemchat str [_res, _arr]; // [[4,1],[2,3]]
```

## See also

[deleteRange](../commands/deleteRange.md) · [set](../commands/set.md) · [resize](../commands/resize.md) · [select](../commands/select.md) · [in](../commands/in.md) · [find](../commands/find.md) · [findIf](../commands/findIf.md) · [toArray](../commands/toArray.md) · [toString](../commands/toString.md) · [forEach](../commands/forEach.md) · [count](../commands/count.md) · [pushBack](../commands/pushBack.md) · [pushBackUnique](../commands/pushBackUnique.md) · [apply](../commands/apply.md) · [append](../commands/append.md) · [sort](../commands/sort.md) · [param](../commands/param.md) · [params](../commands/params.md) · [arrayIntersect](../commands/arrayIntersect.md) · [splitString](../commands/splitString.md) · [joinString](../commands/joinString.md)

## Community notes

**Heeeere's Johnny!** — 2014-10-15

```sqf
_array deleteAt 0;
```

 is almost 60x faster than 

```sqf
_array = _array - [_array select 0]
```

 (Tested with an array of 10.000 strings, iterating through it using a for-from-to-do loop)

---

**Highhead** — 2016-03-04

Deleting from an array with foreach and _foreachIndex variable is tricky.
The 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.
If you delete elements from an array in descending order (using while or for) it will work.

---

**Igneous01** — 2017-02-09

To expand on Highheads comment above - this is because forEach implements iterators to traverse a collection, which are read only by definition.
The variable _x is an iterator that points to the current item in the collection. Trying to alter _x will have no effect.

```sqf
private _array = [1,2,3,4,5,6,7,8];
{ _x = 2; } forEach _array
// _array is still [1,2,3,4,5,6,7,8]
```

When 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.
In short, only use forEach when reading data from an array.
For more info about iterators, see C++ Iterators.

---

**Freghar** — 2021-02-01

As you would expect from a simple array implementation,

```sqf
array deleteAt (count array - 1);
```

is virtually zero cost (0.0005ms on an array of 1000000 elements), while

```sqf
array deleteAt 0;
```

is very performance heavy (0.7ms on the same huge array).

<sub>Source: [BI Community Wiki — deleteAt](https://community.bistudio.com/wiki/deleteAt) (revision 378389).</sub>
