How to use the delete operator In Javascript
The delete operator is used to delete JavaScript objects and object properties.
Syntax:
delete object;
delete object[property];
Example: In this example, we will use the JavaScript delete operator to delete the middle element.
// Input array
let Arr = [1, 2, 3, 4, 5, 6];
// Index of deleting element
let index = Math.floor(Arr.length / 2);
delete Arr[index];
console.log(Arr);
Output
[ 1, 2, 3, <1 empty item>, 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: