Skip to content

Dictionary Prototypes

Dictionary values expose key/value helpers.

let user = {
"name": "Martin",
"age": 19
}
println(user.keys())
println(user.values())

Store a literal in a variable before calling its methods. Direct prototype calls on literals are limited by the current parser.

MethodReturnsDescription
keys()[]KReturns all dictionary keys.
values()[]VReturns all dictionary values.
remove(key: K)voidRemoves a key from the dictionary.

Dictionaries implement internal __get__ and __set__, which power indexed access.

let user = {
"name": "Martin"
}
println(user["name"])
user["role"] = "admin"
println(user["role"])
let config = {
"host": "localhost",
"port": 3000
}
println(config.keys())
println(config.values())
let config = {
"host": "localhost",
"port": 3000
}
config.remove("host")
println(config.keys())

If a key does not exist, direct access can throw an error.

let config = {
"port": 3000
}
catch err {
println(config["host"])
}
if !isNil(err) {
println(err.message)
}