The splice() method is changing the original array and add/remove an element to/from the given position.
It is returning the removed element. And it has three arguments.
Where first argument is “index”, which is an integer to specify at which position add/remove element.
Second argument is “how many”, which is the number of elements to be removed. If this argument is set to 0 then no element will be removed.
And third argument is “element”, which is the new element(s) will be added to the array and this argument is optional.
var vehicles = ["bicycle", "car", "bus"]; vehicles.splice(2,0,"truck"); document.write("Added: " + vehicles + "<br />"); document.write("Removed: " + vehicles.splice(1,2,"tractor,train") + "<br />"); document.write("Vehicles: " + vehicles);