Deletion (from index 1 remove 1 element):
let arr = ["I", "study", "JavaScript"];
arr.splice(1, 1);
alert( arr );
Output: "I", "JavaScript".
Deletion with Replacement (remove 3 first elements and replace them with another):
let arr = ["I", "study", "JavaScript", "right", "now"];
arr.splice(0, 3, "Let's", "dance");
alert( arr );
Output: "Let's", "dance", "right", "now".
Insertion (from index 2 insert 2 elements):
let arr = ["I", "study", "JavaScript"];
arr.splice(2, 0, "complex", "language");
alert( arr );
Output: "I", "study", "complex", "language", "JavaScript".
Negative indexes are allowed. They specify the position from the end of the array.
(from index -1 (one step from the end) delete 0 elements, then insert 3 and 4):
let arr = [1, 2, 5];
arr.splice(-1, 0, 3, 4);
alert( arr );
Output: 1,2,3,4,5