Arrays

Arrays let you store multiple values in a single variable. Declare them with let and square brackets.

Creating arrays

let numbers = [1, 2, 3];
let names = ["Alice", "Bob", "Charlie"];
let empty = [];

Index access

Access elements by index (starting at 0):

let arr = [10, 20, 30];
print(arr[0]);    // 10
print(arr[2]);    // 30

Index assignment

Change an element by assigning to an index — including nested arrays, object fields, and this (v0.1.5+):

let arr = [1, 2, 3];
arr[1] = 99;
print(arr);       // [1, 99, 3]

let m = [[1, 2], [3, 4]];
m[0][1] = 9;      // v0.1.5+ nested assign
print(m);         // [[1, 9], [3, 4]]

arr[0]++;         // v0.1.5+ — ++ works on any lvalue

Reference semantics (v0.1.5+)

Arrays are shared on assignment — copying the variable does not copy the elements:

let a = [1, 2, 3];
let b = a;
push(b, 4);
print(a);         // [1, 2, 3, 4] — a and b are the same array

To get an independent copy, rebuild element-by-element (e.g., loop with push).

len()

Get the length of an array with the built-in len() function:

let arr = [1, 2, 3];
print(len(arr));  // 3

len() also works on strings: len("hello") returns 5.

push()

Append a value to an array with push():

let arr = [1, 2];
push(arr, 3);
print(arr);       // [1, 2, 3]

Printing arrays

let arr = [1, "two", 3];
print(arr);       // [1, "two", 3]

Truthiness

Non-empty arrays are truthy, empty arrays are falsy:

let arr = [1];
if (arr) {
    print("has items");
}

Out of bounds

⚠️ Accessing an index outside the array range throws a runtime error with the index and array size shown.