Skip to content

Arrays

{1, "a", true} makes an array. Arrays can nest: {{1, 2}, {3}}. A trailing comma is allowed (OQ-LANG-29). The empty array {} is only allowed as the whole right side of an assignment.

Indexes start at 0. An index below 0 or past the end reads as empty. The index is turned into a number and cut to a whole number.

function onCreated() {
temp.a = {"x", "y", "z"};
echo(temp.a[1]);
// expect: y
echo(temp.a[5] == NULL);
// expect: 1
echo(temp.a.size());
// expect: 3
}

Run this example in the playground

Writing past the end does nothing. On an array of size 2, arr[4] = "e"; leaves it unchanged. Use .add(value) to grow an array. A write at a negative index does nothing either. Writing an index of an empty variable does nothing (OQ-LANG-30), while writing an index of a variable that holds a list string turns it into an array first.

  • Assigning an array copies it. After temp.b = temp.a; temp.b.add(3);, temp.a is unchanged. This holds for every kind of variable, object field, and array element. Nested arrays are copied deeply (OQ-LANG-31).
  • Passing an array to a function does not copy it. The function works on the caller’s array, so arr.add(9) inside the function changes the caller’s array.
  • A returned array is the same array until it is stored. Storing copies it.
  • Objects inside arrays are always references.
function addNine(arr) {
arr.add(9);
}
function onCreated() {
temp.a = {1, 2};
temp.b = temp.a;
temp.b.add(3);
echo(temp.a.size() @ " " @ temp.b.size());
// expect: 2 3
addNine(temp.a);
echo(temp.a.size());
// expect: 3
}

Run this example in the playground

new[n] makes an array of n empty values. new[rows][columns] makes a grid.

function onCreated() {
temp.grid = new[2][3];
temp.grid[1][2] = "x";
echo(temp.grid[1][2]);
// expect: x
}

Run this example in the playground

Arrays have many methods, such as add, insert, remove, size, sortascending, map, filter, and joinstring. They are listed in the array API. Arrays resolve insert, delete, and remove as array operations when they are called as methods, even on an object that defines functions with those names. The compiler warns about such functions (W-ARRAY-METHOD-NAME).

Text with commas works as an array wherever one is expected, and an array turns into comma text when joined with @. See values and conversions.

An array holds at most 1,000,000 values. A larger one fails the operation with R-LIMIT array.

Engine version 0.1.0. Built 2026-11-18.