API reference / @evolu/common / Array / mapArray

Function: mapArray()

Defined in: packages/common/src/Array.ts:192

Maps an array using a mapper function.

Accepts both mutable and readonly arrays. Preserves non-empty type.

Example

mapArray([1, 2, 3], (x) => x * 2); // [2, 4, 6]

Type Parameters

Type Parameter
T
U

Parameters

ParameterType
arrayreadonly [T, T] | [T, ...T[]]
mapper(item, index) => U

Returns

readonly [U, U]

Defined in: packages/common/src/Array.ts:196

Maps an array using a mapper function.

Accepts both mutable and readonly arrays. Preserves non-empty type.

Example

mapArray([1, 2, 3], (x) => x * 2); // [2, 4, 6]

Type Parameters

Type Parameter
T
U

Parameters

ParameterType
arrayreadonly T[] | T[]
mapper(item, index) => U

Returns

readonly U[]

Was this page helpful?