splice()
ES3+Changes the contents of an array by removing or replacing existing elements and/or adding new elements.
Syntax
array.splice(start, deleteCount, item1, item2, ...)Parameters
start number Index at which to start changing the array
deleteCount number optionalNumber of elements to remove
Return Value
Array
An array containing the deleted elements
Examples
JavaScript
const fruits = ['apple', 'banana', 'cherry'];
fruits.splice(1, 1, 'blueberry', 'blackberry');
console.log(fruits); Output:
// ['apple', 'blueberry', 'blackberry', 'cherry']