API reference@evolu/commonArray › spliceArray

function spliceArray<T>(
  array: readonly T[],
  start: number,
  deleteCount: number,
  ...items: readonly T[]
): readonly T[];

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

Returns a new readonly array with elements removed and/or replaced.

Wraps native toSpliced.

Removing and replacing values

import { assertEqual, spliceArray } from "@evolu/common";

const values: ReadonlyArray<number> = [1, 2, 3, 4];
assertEqual(spliceArray(values, 1, 2), [1, 4]);
assertEqual(spliceArray([1, 2, 3], 1, 1, 10, 11), [1, 10, 11, 3]);
assertEqual(values, [1, 2, 3, 4]);