For the complete documentation index, see llms.txt. This page is also available as Markdown.

Adding & Removing

These methods change the array in place. The mutating ones (append, prepend, insert, swap) return the modified array. pop and shift return the removed element.

.append(item) - mutates

Adds item to the end.

.prepend(item) - mutates

Adds item to the front.

arr = [2, 3]
void arr.append(4)   // arr is now [2, 3, 4]
void arr.prepend(1)  // arr is now [1, 2, 3, 4]

append and prepend return the same array reference, so they can be chained - each call mutates the original array, and pop/shift can end the chain:

arr = []
arr.append(1).append(2).append(3)  // arr is now [1, 2, 3]
log arr.append(4).pop()            // 4, arr is now [1, 2, 3]

.insert(index, item) - mutates

Inserts item before position index (1-indexed).

arr = [1, 3, 4]
void arr.insert(2, 2)  // arr is now [1, 2, 3, 4]

.swap(i, j) - mutates

Swaps the elements at positions i and j (1-indexed).

.pop()unknown

Removes and returns the last element.

.shift()unknown

Removes and returns the first element.

.delete(item)array

Removes item from the array and returns the modified array.

.trim(start, end)array

Returns the slice from position start to end (inclusive, 1-indexed).

Last updated