JavaScriptArraysplice

Changes the contents of an array by removing or replacing existing elements.

Syntax

arr.splice(start, deleteCount?, ...items)

Example

Enter values below to update the example in real time.

const
arr
removed
splice
console
const arr = [1, 2, 3, 4, 5];
const removed = arr.splice(1, 2, 10, 20);
console.log(removed);   // [2, 3]
console.log(arr);       // [1, 10, 20, 4, 5]