Knowledgize

.splice()

Changes the contents of an array by removing or replacing existing elements and/or adding new elements.


Examples:

let fruits = ['apple', 'banana', 'orange']; fruits.splice(2, 0, 'mango'); console.log(fruits); // ['apple', 'banana', 'mango', 'orange']
fruits.splice(1, 2, 'pear', 'grape'); console.log(fruits); // ['apple', 'pear', 'grape', 'orange']