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


# An empty object:
{}
 
# Its type:
{} | type
# "object"
 
# An object literal:
{"a": 97, "b" : 98}
 
# Programmatic object construction:
reduce ("a", "b", "c", "d") as $c ({}; . +  { ($c) : ($c|explode[.0])} )
# {"a":97,"c":99,"b":98,"d":100}
 
# Same as above:
reduce range (97;101) as $i ({}; . + { ([$i]|implode) : $i })
 
# Addition of a key/value pair by assignment:
{}["A"] = 65  # in this case, the object being added to is {}
 
# Alteration of the value of an existing key:
{"A": 65}["A"] = "AA"