JavaScript Array splice() Method

Javascript array splice() method changes the content of an array, adding new elements while removing old elements.

The JavaScript array splice() method is used to add/remove the elements to/from the existing array. It returns the removed elements from an array. The splice() method also modifies the original array.

Parameter Details

  • index − Index at which to start changing the array.

  • howMany − An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed.

  • element1, ..., elementN − The elements to add to the array. If you don't specify any elements, splice simply removes the elements from the array.


array.splice(index, howmany, item1, ....., itemX)


var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(2, 2);

Example -