Standard built-ins

Array.prototype.toSpliced()

Try the free JavaScript compiler

Returns the edited copy after deleting a range and inserting values. Negative start counts from end; omitted skipCount removes through end when start is supplied. Explicit undefined skipCount converts to zero. Does not return removed elements; retained holes are read as undefined.

Formal Syntax & Structure

javascript syntaxjavascript
array.toSpliced(start?, skipCount?, ...items)

Parameters & Attributes

NameTypeDescription
startnumberStart position, normalized to the array bounds.
skipCountnumberNumber to remove; omitted with start supplied means through the end.
itemsany[]Optional values to insert.

Return Value

Array

Edited copy.

Working Example

Example Snippetjavascript
const a=[1,2,3]; console.log(a.toSpliced(1,1,8,9).join(","),a.join(","));
JavaScript Reference