Skip to content

Object Literals

Object literals are data structures that allow key and value pairs to be stored in a static object.

var obj = {{
key = "value",
}};
println(obj.key); // "value"

A key can be assigned the value of the variable using a shorthand notation if the key and variable share the same name.

var key = "value";
var obj = {{ key }};
println(obj.key); // "value"

If the value of the object might be nil, then optional chaining can be used to safely access the value.

var maybe_obj = nil;
println(maybe_obj?.key); // nil