splice javascrit code example
Example 1: javascript splice
let arr = ['foo', 'bar', 10, 'qux'];
arr.splice(1, 1);
arr.splice(2, 1, 'tmp');
arr.splice(0, 1, 'x', 'y');
Example 2: array.splice javascript
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
console.log(months);
months.splice(4, 1, 'May');
console.log(months);
months.splice(0, 1);
console.log(months);
Example 3: splice()
/"removes any number of consecutive elements from anywhere in an array."/
let array = ['today', 'was', 'not', 'so', 'great'];
array.splice(2, 2);
Example 4: Array#splice
let arrDeletedItems = array.splice(start[, deleteCount[, item1[, item2[, ...]]]])