Maps & Hashes

Maps (also known as Hashes or Dictionaries) store associative key-value pairs. They support fast lookups, arbitrary key types, nested structures, and convenient built-in methods.

Creating & Modifying Maps

djazair
let user = {
    "name": "Riyadh",
    "role": "Developer",
    "level": 5,
    "skills": ["C", "Djazair", "Web"]
}

# Accessing keys
print(user["name"])         # => Riyadh

# Updating & Adding keys
user["level"] += 1          # level is now 6
user["city"] = "Blida"      # new key added

# Checking key existence
print("role" in user)       # => True
print(user.has("salary"))   # => False

Map Methods Catalog

Method Description Example
length()Number of key-value pairsuser.length()
has(key)Returns True if key is presentuser.has("name")
get(key)Retrieves value of key (Null if missing)user.get("missing")
keys()Returns an Array of all map keysuser.keys()
values()Returns an Array of all map valuesuser.values()
items()Returns array of [key, value] pairsuser.items()
update(otherMap)Merges another map into this mapuser.update({"active": True})
setDefault(k, v)Sets key to default value if missinguser.setDefault("theme", "dark")
pop(key)Removes and returns value of keyuser.pop("level")
clear()Removes all entries from mapuser.clear()
copy()Creates a shallow copy of the maplet clone = user.copy()

Iterating Over Maps

The for-in loop directly supports key-value destructuring:

djazair
let config = {
    "host": "localhost",
    "port": 8080,
    "debug": True
}

for key, value in config
    print("${key} => ${value}")
end
# host => localhost
# port => 8080
# debug => True