toSpliced() method returns a new array with the specified elements removed or replaced, leaving the original array unchanged.
syntax ↴
toSpliced(index, count, item1, item2, ..., itemN) ↴
index The index (position) to add or remove items.
count (optional). Number of items to be removed.
item1, …, itemN (optional). The new elements(s) to be added.
toSpliced() method returns a new array instead of modifying the original array.
The deleted elements therefore are not returned from this method.
Negative index counts back from the end of the array.
If count is 0 or negative, no elements are removed.
toSpliced(0, 0, ...elements) inserts elements at the start of the array like unshift() method.
Empty slots will be replaced with undefined in the new array.
['a',, 'b', 'c',, 'd'].toSpliced(); returns ↴
['a', undefined, 'b', 'c', undefined, 'd']
toSpliced() method returns a new array with the specified elements removed or replaced; original array is not modified.
splice() method returns an array containing the deleted elements; original array is modified.
myArray.toSpliced(index)
myArray.toSpliced(index, count)
myArray.toSpliced(index, count, item1)
myArray.toSpliced(index, count, item1, item2, ..., itemN)