How to use the splice() method In Javascript
The JavaScript Array splice() Method is an inbuilt method in JavaScript that is used to modify the contents of an array by removing the existing elements and/or by adding new elements.
Syntax:
Array.splice( index, remove_count, item_list )
Example: In this example, we will use the JavaScript splice method to delete the middle element.
// Input array
let Arr = [1, 2, 3, 4, 5, 6];
// Index of deleting element
let middleIndex = Math.floor(Arr.length / 2);
Arr.splice(middleIndex, 1);
console.log(Arr);
Output
[ 1, 2, 3, 5, 6 ]
JavaScript Program to Delete Middle Element from an Array
In this article, we will learn different approaches to how we can delete the middle element from a given array. We will use these JavaScript methods to achieve this: