const Array = ["Mom", "Dad", "Son", "Daughter"] //splice(Starting Index to be removed, No. of elements to be removed following starting index) Array.splice(1,2)
The splice() is great method to edit an array as it does not create a new array and directly make the changes in the Original Array.
But what if you don’t want to edit the original array and create a new array? We use slice() method to get this done.
slice() returns a portion of an array into a new array object. It is to be noted that the last element will not be copied into the new array.
var fruits = ['banana', 'apple', 'orange', 'mango', 'lemon']; var fresh = fruits.slice(1, 4);
['apple', 'orange', 'mango']
Learn more about