Associative array

From Mario Fan Games Galaxy Wiki
Revision as of 18:39, 5 January 2009 by Xgoff (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Associative arrays (also hash or dictionary) are an extension of a normal array; instead of using a numeric index to access values, they use a string key. Generally, only one key of a given name can exist in an associative array.

Commonly, the dot syntax syntactic sugar is provided as an alternative means to access values by providing the key, such as array.key. Otherwise, the value is usually accessed by array["key"].

Languages may or may not sort the keys, e.g. alphabetically; as such, accessing a key's value by using a numeric index instead of a string can be unpredictable. In addition, some may not allow the simultaneous use of both numeric and string indexes, converting array[0] to array["0"].