There are 3 ways in which the splice () method works in javascript:
Delete--You can delete any number of items, just specify 2 parameters: the location of the first item to delete and the number of items to delete.
For example, splice (0,2) deletes the first two items in the array.
Insert--You can insert any number of items to the specified location, providing only 3 parameters: Insert starting position, 0 (number of items to delete), and items to insert. If you want to insert more than one item, you can pass in four, five, any number of items.
For example, splice (2,0, "Red", "green") will insert the string "red" and "green" starting at position 2.
Replace-A comprehensive application that deletes and inserts the number of equal items, you can insert any number of items at the specified location, and delete any number of items at the same time by specifying 3 specified parameters: The starting position, the number of items to delete, and any number of items to insert. The number of items inserted is not necessarily equal to the number of items deleted.
For example, splice (2,2, "Red", "green") removes the entry for the current array position 2, and then inserts the string "Red" and "green" starting at position 2.
The splice () method always returns an array that contains the items removed from the array of elements (an empty array is returned if no items are deleted).
Usage of "javascript" slice ()