.splice()

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

Syntax

Loading...
  • start: The array index at which the insertion and/or removal is to begin.

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.

Loading...
  • start: The array index at which the insertion and/or removal is to begin.
  • length (optional): The number of elements in the array to remove beginning at start.
Loading...
  • start: The array index at which the insertion and/or removal is to begin.
  • length (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.

Examples

Remove 'Saturday' and 'Sunday' from the daysOfWeek array:

Loading...

Remove the months from the daysOfWeek array:

Loading...

Replace 'WEDNESDAY' with 'Wednesday' in daysOfWeek array :

Loading...

Add 'Saturday' and 'Sunday' to the end of daysOfWeek array :

Loading...
Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn JavaScript on Codecademy