API reference / @evolu/common / Array / prependToArray
Function: prependToArray()
function prependToArray<T>(array, item): readonly [T, T];
Defined in: packages/common/src/Array.ts:174
Prepends an item to an array, returning a new non-empty readonly array.
Accepts both mutable and readonly arrays. Does not mutate the original array.
Example
prependToArray([2, 3], 1); // [1, 2, 3]
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
array | readonly T[] |
item | T |
Returns
readonly [T, T]