Delete Operation

Delete operation refers to the removal of an object property. It can be done as follows:

  • Using Delete operator: Delete keyword is used to remove the object property mentioned after it.
  • Using Destructuring Assignment: It refers to the JavaScript syntax for unpacking the object values and assigning them to other variables.

Syntax

delete obj.propety  or  delete obj['property']        // Using delete operator
const {property1, newObj} = oldObj; // Using destructuring

Example: This example describes the deletion of the Object & its associated properties & values.

Javascript




const obj = {
    name: 'xyz',
    age: 52,
    city: 'delhi'
}
  
  
// Display original object
console.log("Original object: ", obj);
  
// Using destructuring
const { age, ...newObj } = obj;
console.log("New object without age attribute: ", newObj);
  
  
// Using delete operator
delete obj.city;
console.log("Original object after deleting city: ", obj);


Output

Original object:  { name: 'xyz', age: 52, city: 'delhi' }
New object without age attribute:  { name: 'xyz', city: 'delhi' }
Original object after deleting city:  { name: 'xyz', age: 52 }


How to Perform CRUD Operations on JavaScript Object ?

This article will demonstrate the CRUD Operations on a JavaScript Object. The operations are Create, Read, Update, and Delete. With these operations, we can create, take input, manipulate & destroy the objects.

JavaScript Objects are a collection of keys, values or properties/attributes, and entries. The values can be any data type as well as JavaScript functions, arrays, etc.

Syntax

// Creating an Object
const rectangle = {
length: 25,
width: 20,
area: function(){
return this.length*this.width;
}
}

Similar Reads

CRUD operations in JavaScript Objects

Create: Create a new object or add an object property to an existing object. Read: Read any object existing property property Update: Update or modify an object or the attribute values. Delete: Delete or remove an entry from an object or the whole object....

Create Operation

This operation refers to the creation of an object or adding a new property to it. The following methods can be used to create the Object:...

Read Operation

...

Update Operation

The read operation refers to reading and accessing the properties and values of an object. It can be done using the following methods:...

Delete Operation

...