The splice() method is used to add/remove items to/from an array, and returns the removed item(s).
Syntax
array.splice(index, howMany, [element1][, ..., elementN]);
where
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.
Example:
var arr = ["one", "two", "three", "seven", "ten"];
var removed = arr.splice(2, 0, "eleven");
document.write("After adding 1: " + arr );
document.write("<br />removed is: " + removed);
removed = arr.splice(3, 1);
document.write("<br />After adding 1: " + arr );
document.write("<br />removed is: " + removed);
0 Comment(s)