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


fn main() {
    // make empty map
    mut my_map := map[string]int{}
 
    //s et value
    my_map['foo'] = 3
 
    // getting values
    y1 := my_map['foo']
 
    // remove keys
    my_map.delete('foo')
 
    // make map with values
    my_map = {
        'foo': 2
        'bar': 42
        'baz': -1
    }
}