API reference › @evolu/common › Array › arrayFrom
Call Signature
function arrayFrom<T>(iterable: Iterable<T>): readonly T[];
Defined in: packages/common/src/Array.ts:180
Better Array.from.
- Returns readonly arrays
- Accepts length directly:
arrayFrom(3, fn)instead ofArray.from({ length: 3 }, fn) - Skips copying if iterable is already an array (safe because readonly)
Example
arrayFrom(new Set([1, 2, 3])); // ReadonlyArray<number>
arrayFrom(3, (i) => i * 10); // [0, 10, 20]
arrayFrom(iterableMaybeArray); // no unnecessary copy
Unlike Array.from, there's no map parameter for iterables — use
mapArray instead, or
iterator helpers
directly on iterables.
Call Signature
function arrayFrom<T>(length: number, map: (index: number) => T): readonly T[];
Defined in: packages/common/src/Array.ts:182
From length and map function.