Function Updated 17 Oct 2026
Array.splice(start, [deleteCount], [item1...N])
Changes the contents of an array by removing or replacing existing elements and/or adding new elements at specified index.
Parameters
startintrequiredIndex where items are removed and inserted. A negative value counts from the end of the array.
deleteCountintoptionalNumber of items to remove. If omitted, every item from start to the end is removed.
item1...NobjectoptionalItems to insert at start (zero or more).
Returns
An array of the items that were removed. The array itself is changed.
Example
Normal JavaScript, running in the browser or on the Docly™ server.
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
/* Inserts at index 1 */
write(JSON.stringify(months));
/* Expected output: ["Jan","Feb","March","April","June"] */
write("\n");
months.splice(4, 1, 'May');
/* Replaces 1 element at index 4 */
write(JSON.stringify(months));
/* Expected output: ["Jan","Feb","March","April","May"] */The JavaScript above produces this output:
["Jan","Feb","March","April","June"]
["Jan","Feb","March","April","May"]