Published Jun 22, 2021Updated Jul 30, 2022
Contribute to Docs

The .splice() method modifies an array in place by inserting, removing, and/or replacing array elements then returning an array of removed elements.


array.splice(start, itemCount, item1, item2, ..., itemN);
  • start: The array index at which the insertion and/or removal is to begin.
  • itemCount (optional): The number of elements in the array to remove beginning at start.
  • item1, item2,..., itemN (optional): The elements that will be inserted into the array at start.

If only the start index is provided then it will remove all the elements from start to the end of the array.

A negative start value indicates an offset from the end of the array.


The following example adds 'Saturday' and 'Sunday' to the end of the daysOfWeek array:

const daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
daysOfWeek.splice(5, 0, 'Saturday', 'Sunday');

The output will look like this:


Codebyte Example

The following example removes the months and then replaces 'Wednesday' with 'WEDNESDAY' in the daysOfWeek array:

Visit us
Hide code
Hide output
Hide output

All contributors

Looking to contribute?

Learn JavaScript on Codecademy