Standard library / Array methods · on the one-page reference
Array methods
Stable —
fixed-size []const T slices underneath; no allocation, no
growable-array machinery, conformance-covered.
Called directly on any T[] value; callbacks are
written as typed arrow functions.
| API | Type |
|---|---|
a[i] · a.length · a.at(i) | element access · int · T | null (at allows negative index) |
a.map(fn) | ((T) => U) or ((T, int) => U) → U[] (optional index) |
a.flatMap(fn) | ((T) => U[]) or ((T, int) => U[]) → U[] (each callback's array concatenated into one flat array) |
a.filter(fn) | ((T) or (T, int) => bool) → T[] (optional index) |
a.reduce(fn, init) · a.reduceRight(fn, init) | (((U, T) or (U, T, int) => U), U) → U (optional index; reduceRight folds from the end) |
a.forEach(fn) | ((T) => void) or ((T, int) => void) → void (optional index) |
a.find(fn) · a.findIndex(fn) · a.some(fn) · a.every(fn) | ((T) or (T, int) => bool) predicate → T · int · bool · bool (optional index) |
a.findLast(fn) · a.findLastIndex(fn) | same predicate, scanning from the end → T | null · int |
a.indexOf(x, from?) · a.lastIndexOf(x, from?) · a.includes(x, from?) | → int · int · bool (from allows negative index; lastIndexOf searches backward from it) |
a.slice(start, end?) · a.reverse() · a.concat(b) · a.with(i, v) · a.fill(v, start?, end?) · a.copyWithin(target, start?, end?) | → T[] (new array; source unchanged; with replaces index i; fill sets [start, end); copyWithin copies a block to target; negatives from the end) |
a.sort(cmp) · a.toSorted(cmp) | ((T, T) => int) → T[] (new, stable; cmp<0 ⇒ a first) |
a.toReversed() | → T[] (alias of reverse; new array) |
a.join(sep?) · a.toString() | → string (sep defaults to ","; toString is the comma-joined form) |
Array.isEmpty(a) | T[] → bool |
Array.of(...items) | (T, …) → T[] (new array from the arguments) |
new Array(n).fill(v) · Array(n).fill(v) | (int, T) → T[] (an n-length array with every element v) |
Array.from(x) · Array.from(x, (v, i?) => u) | string → string[] (chars) · T[] → T[] (copy) · Set<T> → T[]; with a map callback → u[] (each element mapped, optional index) |
Array.isArray(x) | any → bool — a compile-time verdict (types are static), true for any array value |
Object.keys(record) | T → string[] — the record type's field names, in declaration order (static shape) |