1let myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon']
2let removed = myFish.splice(3, 1)
3
4// myFish is ["angel", "clown", "drum", "sturgeon"]
5// removed is ["mandarin"]
1let myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
2//insert new element into array at index 2
3let removed = myFish.splice(2, 0, 'drum')
4
5// myFish is ["angel", "clown", "drum", "mandarin", "sturgeon"]
6// removed is [], no elements removed
1Check Out my CODE-PEN for this Solution
2
3https://codepen.io/siddhyaOP/pen/eYgRGOe
4https://codepen.io/siddhyaOP/pen/eYgRGOe
5https://codepen.io/siddhyaOP/pen/eYgRGOe
1var arr = ["orange", "mango", "banana", "sugar", "tea"];
2var removed = arr.splice(2, 0, "water");
3console.log(arr); // orange,mango,water,banana,sugar,tea
4console.log(removed); // banana
1const numbers = [2, 4, 5, 3, 8, 9, 11, 33, 44];
2const spliceNumbers = numbers.splice(0, 5)
3//start from 0 && remove next 5 elements
4console.log(spliceNumbers)
5//Expected output:[ 2, 4, 5, 3, 8 ]
1Splice and Slice both are Javascript Array functions. Splice vs Slice. The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object. The splice() method changes the original array and slice() method doesn't change the original array.27-Jan-2018