Associative array

An associative array is a special kind of array. Each element has a name or label instead of just a number. Usually, arrays use numbers to find things. With an …

An associative array is a special kind of array. Each element has a name or label instead of just a number. Usually, arrays use numbers to find things. With an associative array, the name or label is related to the element, as key to value (key-value or name-value). The key represents a name or label, that can be used to find the value of an element.

Example

  • The associative array is assigned to a variable (var).
  • The "key" is used to find the "value" it contains.
var := {
    "key_1": "value_1",
    "key_2": "value_2",
    "key_3": "value_3"
}

Uses

Associative arrays, depending on the programming language, can be known by many different names. Such as: hashmap, hash table, hash, map, table, or dictionary.

In Objective-C, .NET,[1] Python, Swift, VBA they are called dictionaries; in Perl, Ruby they are called hashes; in C++, C#, Go, Haskell, Java, OCaml, Scala, and V (Vlang)[2] they are called maps; in Lisp (Common Lisp) and Windows PowerShell, they are called hash tables; in Maple and Lua, they are called tables. In the D language they are called hash maps.[3]

In JavaScript (see also JSON), all objects behave as associative arrays with string-value keys, while the Map and WeakMap types take objects as keys. In Lua, they are used as the building blocks for their data structures. In PHP and R, all arrays can be associative, but the keys are limited to integers and strings.

References

  1. ↑ "Dictionary<TKey, TValue> Class". MSDN.
  2. ↑ Rao, Navule Pavan Kumar (December 10, 2021). Getting Started with V Programming. p. 103. ISBN 978-1839213434. OCLC 1290492862.
  3. ↑ "Associative Arrays, the D programming language". Digital Mars.


Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.