function splice
splice<T>(
list: T[],
start: number,
deleteCount?: number,
items?: T[]
): T[]

Returns a new array with elements removed and/or inserted, without mutating the original.

Examples

Example 1

splice([1, 2, 3, 4], 1, 2) // [1, 4]
splice([1, 2, 3], 1, 0, [9, 10]) // [1, 9, 10, 2, 3]
splice([1, 2, 3, 4], 2) // [1, 2] — omitting deleteCount removes from start to end

Type Parameters

Parameters

list: T[]

The source array

start: number

Index at which to start changing the array

optional
deleteCount: number

Number of elements to remove

optional
items: T[]

Elements to insert at the start index

Return Type

T[]

A new array with the modifications applied

Usage

import { splice } from ".";