API reference@evolu/commonArray › createMutableArray

function createMutableArray<T>(length: number): T[];

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

Creates a mutable sparse Array with the specified length.

Use it to build an Array with indexed writes when its final length is known. Assign every index before exposing the completed Array as readonly.

Example

import { createMutableArray } from "@evolu/common";

const values = createMutableArray<number>(3);

for (let index = 0; index < values.length; index++) {
  values[index] = index * 10;
}

expect(values).toEqual([0, 10, 20]);
expectTypeOf(values).toEqualTypeOf<Array<number>>();