splice method js

JavaScript
let arr = ['foo', 'bar', 10, 'qux'];

// arr.splice(<index>, <steps>, [elements ...]);

arr.splice(1, 1);			// Removes 1 item at index 1
// => ['foo', 10, 'qux']

arr.splice(2, 1, 'tmp');	// Replaces 1 item at index 2 with 'tmp'
// => ['foo', 10, 'tmp']

arr.splice(0, 1, 'x', 'y');	// Inserts 'x' and 'y' replacing 1 item at index 0
// => ['x', 'y', 10, 'tmp']const numbers = [10, 11, 12, 12, 15];
const startIndex = 3;
const amountToDelete = 1;

numbers.splice(startIndex, amountToDelete, 13, 14);
// the second entry of 12 is removed, and we add 13 and 14 at the same index
console.log(numbers);
// returns [ 10, 11, 12, 13, 14, 15 ]
let myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
//insert new element into array at index 2
let removed = myFish.splice(2, 0, 'drum')

// myFish is ["angel", "clown", "drum", "mandarin", "sturgeon"] 
// removed is [], no elements removed/"splice() can also switch out an element, or a set of elements, for another."/
const numbers = [10, 11, 12, 12, 14];

numbers.splice(3, 1, 13);
// the second entry of 12 is removed, and we add 13 at the same index
console.log(numbers);
// returns [ 10, 11, 12, 13, 14, 15 ]
Source

Also in JavaScript: