Task

The goal is to create an associative array (also known as a dictionary, map, or hash).



Related tasks:

 Associative arrays/Iteration
 Hash from two arrays


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


# Create one element at a time:
set hash(foo) 5
 
# Create in bulk:
array set hash {
    foo 5
    bar 10
    baz 15
}
 
# Access one element:
set value $hash(foo)
 
# Output all values:
foreach key [array names hash] {
    puts $hash($key)
}