Learn JavaScript
Advanced Array Methods
31.9
Lesson

splice()

The splice() method can modify an array by inserting, removing or replacing elements. It returns an array of the removed elements.

In the example given above, starting from index 1, splice removes 3 elements from the numbersarray. The variableremovedItems stores the removed elements.

In the example given above, it removes the element mango at index 2 and inserts the element kiwi in its place.

In the example given above, it adds the element kiwi at index 2 without removing any element.