Skip to content

Collections

Lists are ordered collections of values.

Create a list with square brackets:

const numbers = [1, 2, 3, 4, 5]
const words = ["hello", "world"]

Lists can span multiple lines:

const words = [
"hello",
"world",
"example"
]

Use [] to create an empty list:

const empty = []
const one = [1]

Lists can contain mixed values when needed:

const mixed = [1, "two", 3.0, true]
println(mixed)

Access a list item with square brackets:

let all = regex("a\\d+").findAll("x a123 y a456")
for i in all.length() {
println(all[i])
}

Values that support length() can report their size:

const words = ["hello", "world"]
println(words.length())

A common pattern is to loop over list.length() and index into the list:

const numbers = [1, 2, 3]
for i in numbers.length() {
println(numbers[i])
}