# createHashMapFromArray ## Category HashMap ## Arity **Unary** — `createHashMapFromArray `. ``` createHashMapFromArray // [key1, val1, key2, val2, ...] ``` ## Description Creates a new hashmap pre-populated from a flat array of alternating keys and values. The array must have an even number of elements: `[key1, val1, key2, val2, ...]`. If the array has an odd length, the last key without a value is ignored. ## How It Works Iterates the array in pairs, inserting each `(key, value)` into a new `Dictionary`. The resulting hashmap is mutable and owned by the current scheduler. Duplicate keys: later values overwrite earlier ones. ## Usage ### Create with initial data ```sqf _map = createHashMapFromArray ["a", 1, "b", 2, "c", 3]; _map get "b"; // 2 _map get "a"; // 1 ``` ### Quick config ```sqf _settings = createHashMapFromArray [ "volume", 0.8, "music", true, "difficulty", "normal" ]; ``` ### From variables ```sqf _name = "player"; _hp = 100; _alive = true; _entity = createHashMapFromArray [ "name", _name, "hp", _hp, "alive", _alive ]; ``` ### Duplicate keys ```sqf _map = createHashMapFromArray ["key", 1, "key", 2]; _map get "key"; // 2 (later overwrites earlier) ``` ## Thread Safety **Not thread-safe**. HashMap must be owned by the current scheduler. ## See Also - [createHashMap](createHashMap.md) — create empty hashmap - [get](get.md) — retrieve value by key - [set](set.md) — store key-value pair