---
name: "set"
type: command
status: ok
groups: ["Arrays", "HashMap"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/set
revid: 377132
updated: 2026-01-01T10:26:06Z
---

# set

*Command · Arrays, HashMap · Arma 3 v0.50 · introduced in Operation Flashpoint v1.75*

## Description

Changes the element at the given zero-based index of the [array](../topics/Array.md).

> [!NOTE]
> If the index is out of bounds, the array will [resize](../commands/resize.md) to incorporate the index as its last value, padding with [nil](../commands/nil.md) as necessary (see [#Example 4](../commands/set.md#example-4)).

## Syntax

### Syntax 1

```sqf
array set [index, value]
```

**Parameters:**

- `array`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `index`: [Number](../topics/Number.md) - 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.
- `value`: [Anything](../topics/Anything.md)

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

### Syntax 2

*since arma3 2.02*

```sqf
hashMap set [key, value, insertOnly]
```

**Parameters:**

- `hashMap`: [HashMap](../topics/HashMap.md)
- `key`: [HashMapKey](../topics/HashMapKey.md)
- `value`: [Anything](../topics/Anything.md)
- `insertOnly`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) if set to [true](../commands/true.md), set the value only if the key does not exist already *(since arma3 2.08)*

**Returns:** [Boolean](../topics/Boolean.md) - [false](../commands/false.md) if the key is new to the hashmap, [true](../commands/true.md) if a value got overwritten

## Examples

### Example 1

```sqf
_arrayOne set [0, "Hello"];
```

### Example 2

Append "Bye" as last element to `_arrayTwo`:

```sqf
_arrayTwo set [count _arrayTwo, "Bye"];
```

### Example 3

Replace the last element of `_arrayThree` with 23:

```sqf
_arrayThree set [(count _arrayThree) - 1, 23];
```

### Example 4

Using [set](../commands/set.md) with an index that is out of bounds:

```sqf
private _array = ["A"];
_array set [2, "C"]; // _array is now ["A", nil, "C"]
_array set [1, "B"]; // _array is now ["A", "B", "C"]
```

### Example 5

```sqf
private _myHashMap = createHashMap;
_myHashMap set ["key", "value1", true]; // "key" value is set to "value1"
_myHashMap set ["key", "value2", true]; // "key" value is still "value1" as "key" already exists in the hashmap
```

## See also

[resize](../commands/resize.md) · [reverse](../commands/reverse.md) · [select](../commands/select.md) · [deleteAt](../commands/deleteAt.md) · [deleteRange](../commands/deleteRange.md)

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