Maps are ordered key-value dictionaries. Keys are always stored as strings; values can be any type. Insertion order is preserved.
Literal Syntax
let user = {
name: "Alice",
age: 30,
active: true
}
Bare identifiers (name:) are treated as string keys. String literals can also be used:
let config = {
"host": "localhost",
"port": 8080
}
An empty map is {}.
Reading Values
Bracket notation (dynamic key):
let name = user["name"] // "Alice"
Dot notation (static key — must be a valid identifier):
let age = user.age // 30
A missing bracket key returns null. A missing dot key raises a Type Error. Dot names such as length and keys resolve to built-in properties or methods first; use brackets to read keys with those names.
Writing Values
user["city"] = "Nairobi" // bracket notation
user["score"] = 100 // use brackets for assignment
Key Membership
The in operator checks whether a key exists in a map:
if "name" in user {
print("name is set")
}
if "email" not in user {
print("no email on file")
}
Map Methods
See §15 Map Methods for the full method reference.
Maps and len()
let m = {a: 1, b: 2, c: 3}
print(len(m)) // 3