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:



Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy