---
name: "getOrDefault"
type: command
status: ok
groups: ["HashMap"]
arma3_since: "2.02"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/getOrDefault
revid: 348340
updated: 2023-11-08T12:59:48Z
---

# getOrDefault

*Command · HashMap · Arma 3 v2.02*

## Description

Retrieves a value out of a [HashMap](../topics/HashMap.md) after looking it up by its key. When the HashMap doesn't contain the key, the default value is returned

## Syntax

```sqf
hashMap getOrDefault [key, defaultValue, setDefault]
```

**Parameters:**

- `hashMap`: [HashMap](../topics/HashMap.md)
- `key`: [HashMapKey](../topics/HashMapKey.md) - case sensitive key
- `defaultValue`: [Anything](../topics/Anything.md) - (Optional, default [nil](../commands/nil.md))
- `setDefault`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) if set to [true](../commands/true.md) and value does not exist in provided hash map, *defaultValue* will be added to the hash map *(since arma3 2.04)*

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

## Examples

### Example 1

```sqf
private _myValue = _myHashMap getOrDefault ["a", "Not Found!"];
```

### Example 2

```sqf
private _myValue = _hashMap getOrDefault ["a", "Not Found!", true]; // will add default value to the hash map if it does not exist
```

### Example 3

```sqf
private _array = _hashmap getOrDefault [_key, [], true]; // a new array will be created if it doesn't exist
_array pushBack _item; // _item will be added to the array (the one in the hashmap is updated by reference)
```

## See also

[getOrDefaultCall](../commands/getOrDefaultCall.md) · [HashMap](../topics/HashMap.md) · [get](../commands/get.md)

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