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.

Javascript
// 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:

Similar Reads

Methods to Delete Middle Element from an Array

Table of Content Methods to Delete Middle Element from an ArrayUsing JavaScript Spread OperatorUsing the JavaScript splice() methodUsing the JavaScript delete operatorUsing JavaScript array.filter() MethodUsing Array.slice() method...

Using JavaScript Spread Operator

The Spread operator allows an iterable to expand in places where 0+ arguments are expected. It is mostly used in the variable array where there is more than 1 value is expected....

Using the JavaScript splice() method

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....

Using the JavaScript delete operator

The delete operator is used to delete JavaScript objects and object properties....

Using JavaScript array.filter() Method

The JavaScript Array filter() Method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument method....

Using Array.slice() method

The JavaScript Array.slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included). We can utilize this method to exclude the middle element from the array....