Skip to content

array: members

52 implemented, 1 reserved. Entries are sorted by name.

array.add(value: any)

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Appends a value at the end of the array. An array given as the value is copied first, so later changes to it do not reach the list.

temp.items.add("sword");

Specification: standard-library.md§5.1.

array.addarray(other: array)

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Appends copies of all elements of another array, or of a list string, to the end of this array.

temp.items.addarray({"x", "y"});

Specification: standard-library.md§5.1.

array.at(index: number) -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns the element at the position; a negative position counts back from the end and one outside the array gives empty.

echo(temp.items.at(-1));

Specification: standard-library.md§5.3.

array.chunk(size: number) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Splits the array into a new array of sub-arrays holding at most size elements each. A size below 1 gives an empty array.

temp.rows = temp.items.chunk(3);

Specification: standard-library.md§5.3.

array.clear()

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Removes every element from the array.

temp.items.clear();

Specification: standard-library.md§5.1.

array.concat(...parts?: any) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a new array made of this array followed by each argument; array arguments contribute their elements and other arguments are added as single elements.

temp.all = temp.a.concat(temp.b, "extra");

Specification: standard-library.md§5.3.

array.copy() -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a shallow copy: a new array holding the same elements.

temp.dup = temp.items.copy();

Specification: standard-library.md§5.3.

array.delete(index: number)

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Removes the element at the given position. A position outside the array does nothing.

temp.items.delete(0);

Specification: standard-library.md§5.1.

array.every(callback: function) -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns 0 as soon as the callback rejects an element, otherwise 1 (also for an empty array).

echo(temp.nums.every(function(n) { return n > 0; }));

Specification: standard-library.md§5.3.

array.fill(value: any, start?: number, end?: number) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Sets the elements from start up to, not including, end to copies of the value, in place, and returns the array.

temp.slots.fill(0);

Specification: standard-library.md§5.3.

array.filter(callback: function) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a new array with the elements for which the callback result counts as true. An array result always counts as false.

temp.big = temp.nums.filter(function(n) { return n > 10; });

Specification: standard-library.md§5.3.

array.find(callback: function) -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns the first element for which the callback result counts as true, or empty when none does.

temp.hit = temp.nums.find(function(n) { return n > 3; });

Specification: standard-library.md§5.3.

array.findindex(callback: function) -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns the position of the first element the callback accepts, or -1.

temp.at = temp.nums.findindex(function(n) { return n > 3; });

Specification: standard-library.md§5.3.

array.findlast(callback: function) -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns the last element for which the callback result counts as true, or empty when none does.

temp.hit = temp.nums.findlast(function(n) { return n > 3; });

Specification: standard-library.md§5.3.

array.findlastindex(callback: function) -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns the position of the last element the callback accepts, or -1.

temp.at = temp.nums.findlastindex(function(n) { return n > 3; });

Specification: standard-library.md§5.3.

array.flat(depth?: number) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a new array with nested arrays spread out, one level deep unless a depth is given.

temp.flatter = temp.nested.flat(2);

Specification: standard-library.md§5.3.

array.flatmap(callback: function) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Maps every element through the callback and spreads one level of array results into the new array.

temp.pairs = temp.nums.flatmap(function(n) { return {n, n * 2}; });

Specification: standard-library.md§5.3.

array.foreach(callback: function)

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Calls the callback once per element with the element, its index, and the array. The element count is fixed when the loop starts.

temp.items.foreach(function(item, i) { echo(i @ ": " @ item); });

Specification: standard-library.md§5.3.

array.groupby(callback: function) -> object

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a TStaticVar whose fields are the keys the callback returned (as text) and whose values are arrays of the elements with that key.

temp.groups = temp.items.groupby(function(i) { return i.length(); });

Specification: standard-library.md§5.3.

array.includes(value: any, from?: number) -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns 1 when an element equals the value under loose comparison, starting the search at from; a negative from counts back from the end.

echo(temp.items.includes("sword"));

Specification: standard-library.md§5.3.

array.index(value: any) -> number

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Returns the position of the first element equal to the value under loose comparison, or -1 when there is none.

echo(temp.items.index("sword"));

Specification: standard-library.md§5.1.

array.insert(index: number, value: any)

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Inserts a value before the given position. A position at or beyond the size, or a negative one, appends it.

temp.items.insert(1, "shield");

Specification: standard-library.md§5.1.

array.insertarray(index: number, other: array)

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Inserts the elements of another array at an index: past the end appends, a negative index inserts at the front.

temp.a.insertarray(1, {8, 9});

Specification: standard-library.md§17.4.7.

array.isempty() -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns 1 when the array has no elements, otherwise 0.

if (temp.items.isempty()) echo("none");

Specification: standard-library.md§5.3.

array.joinstring(separator?: string) -> string

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Joins the text forms of all elements with the separator, a comma by default, without adding any quotes.

echo(temp.names.joinstring(", "));

Specification: standard-library.md§5.3.

array.lastindex(value: any) -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns the position of the last element equal to the value under loose comparison, or -1.

echo(temp.items.lastindex("sword"));

Specification: standard-library.md§5.3.

array.length: number

Runs on: server and client. Origin: compatibility. Since: M1. Playground: no. read-only.

The number of elements of the array.

echo(temp.a.length);

Specification: standard-library.md§17.4.8.

array.link() -> array

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Returns the very same array, which lets a call chain continue on it without copying.

temp.items.link().add("z");

Specification: standard-library.md§5.1.

array.loadfolder(pattern: string, recursive?: number) -> boolean

Runs on: server and client. Origin: compatibility. Since: M4. Playground: no.

Replaces the elements with the paths of the files that match a pattern such as levels/*.png, sorted; a true second argument also searches the folders below, eight levels deep.

temp.files.loadfolder("levels/*.nw", 1);

Specification: standard-library.md§17.4.3.

array.map(callback: function) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a new array holding what the callback returned for each element.

temp.doubled = temp.nums.map(function(n) { return n * 2; });

Specification: standard-library.md§5.3.

array.pop() -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Removes the last element and returns it, or returns empty when the array has none.

temp.last = temp.stack.pop();

Specification: standard-library.md§5.3.

array.push(...values?: any) -> number

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Appends all the given values at the end and returns the new element count.

temp.count = temp.items.push("a", "b");

Specification: standard-library.md§5.1.

array.reduce(callback: function, initial?: any) -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Folds the elements from first to last into one value; the callback gets the running value, the element, its index, and the array. Without an initial value the first element starts the fold.

temp.total = temp.nums.reduce(function(acc, n) { return acc + n; }, 0);

Specification: standard-library.md§5.3.

array.reduceright(callback: function, initial?: any) -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Like reduce, but walks the elements from the last to the first.

temp.text = temp.parts.reduceright(function(acc, p) { return acc @ p; }, "");

Specification: standard-library.md§5.3.

array.remove(value: any)

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Removes the first element that equals the value under loose comparison and leaves any later duplicates alone.

temp.items.remove("sword");

Specification: standard-library.md§5.1.

array.replace(index: number, value: any)

Runs on: server and client. Origin: compatibility. Since: M12. Playground: yes.

Sets the element at the given position. A position at or beyond the size, or a negative one, appends the value instead.

temp.a = {1, 2, 3}; temp.a.replace(1, 9); // 1,9,3

Specification: standard-library.md§5.1.

array.reverse() -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Reverses the order of the elements in place and returns the array.

temp.items.reverse();

Specification: standard-library.md§5.3.

array.savelines(path: string, mode: number) -> number

Runs on: server and client. Origin: engine extension. Since: M4. Playground: no.

Writes the array as lines, each ending with a line feed. Mode 0 replaces the file, mode 1 appends. Returns 1 on success.

temp.lines.savelines("logs/out.txt", 0);

Specification: standard-library.md§12.2.

array.shift() -> any

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Removes the first element and returns it, or returns empty when the array has none.

temp.first = temp.queue.shift();

Specification: standard-library.md§5.3.

array.size() -> number

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Returns how many elements the array holds. A list string reports its element count, and any other text, a number, or an unset variable reports 0.

echo(temp.list.size());

Specification: standard-library.md§5.1.

array.slice(start: number, end?: number) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a new array with copies of the elements from start up to, not including, end. Negative positions count back from the end.

temp.tail = temp.items.slice(-2);

Specification: standard-library.md§5.3.

array.some(callback: function) -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns 1 as soon as the callback accepts an element, otherwise 0 (also for an empty array).

echo(temp.nums.some(function(n) { return n > 3; }));

Specification: standard-library.md§5.3.

array.sortascending()

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Sorts the array in place by the text form of its elements, ignoring capital letters; texts that differ only in case put small letters first. Numbers are compared as text too, so 10 comes before 9.

temp.items.sortascending();

Specification: standard-library.md§5.1.

array.sortby(comparator: function) -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Sorts the array in place with a comparator that gets two elements and returns a negative, zero, or positive number. Equal elements keep their order.

temp.nums.sortby(function(a, b) { return a - b; });

Specification: standard-library.md§5.3.

array.sortbyvalue(member: string, type: string, ascending: any) -> array

Runs on: server and client. Origin: compatibility. Since: M14. Playground: yes.

Sorts an array of objects by one variable of each element, as text when the type is “string” and as numbers otherwise, ascending when the last argument is true.

temp.list.sortbyvalue("score", "float", false);

Specification: standard-library.md§5.1.

array.sortdescending()

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Sorts the array in place by the text form of its elements in reverse order, ignoring capital letters.

temp.items.sortdescending();

Specification: standard-library.md§5.1.

array.splice(start: number, count?: number) -> array

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Cuts count elements out of the array starting at start and returns them as a new array. Without a count everything from start to the end is cut.

temp.removed = temp.items.splice(1, 2);

Specification: standard-library.md§5.1.

array.subarray(start: number, count?: number) -> array

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Returns a new array holding copies of count elements beginning at start, leaving the original unchanged.

temp.part = temp.items.subarray(0, 3);

Specification: standard-library.md§5.1.

array.subarray2(start1: number, length1: number, start2: number, length2: number) -> array

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Returns rows start1 to start1+length1 of a two-dimensional array, each cut to the columns start2 to start2+length2.

temp.part = temp.grid.subarray2(0, 2, 1, 2);

Specification: standard-library.md§17.4.7.

array.sum() -> number

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Adds up the elements that are numbers or numeric strings and skips everything else.

echo(temp.nums.sum());

Specification: standard-library.md§5.3.

array.unique() -> array

Runs on: server and client. Origin: engine extension. Since: M1. Playground: yes.

Returns a new array without repeated elements, comparing loosely and keeping the first of each group.

temp.once = temp.items.unique();

Specification: standard-library.md§5.3.

array.unshift(...values?: any) -> number

Runs on: server and client. Origin: compatibility. Since: M1. Playground: yes.

Puts the given values in front of the existing elements, in the order written, and returns the new element count.

temp.items.unshift("first");

Specification: standard-library.md§5.1.

These names exist so that older scripts compile. Calling one reports R-NOT-IMPLEMENTED and does nothing else.

Name Signature Runs on
array array.array(...params?: any) -> any client only (not yet verified)

Engine version 0.1.0. Built 2026-11-18.