For deleting objects or the properties of an object, utilize the “delete” operator. It removes or deletes the properties from an object. It takes an object property as its operand and removes the property from the object. The delete operator outputs “true” if the property was successfully deleted and “false” if it couldn’t be deleted because it is a non-configurable property.
The following syntax is used for the delete operator:
First of all, create an object:
Call the “delete” operator for deleting object:
Print the object on the console. After deleting, it will display on the console because the delete operator removes only a reference to an item, never the object itself:
There is no need to delete objects, they will be deleted if there are no means of referring to them. You can delete the object’s properties that are not relevant or needed.
Here, we will delete the “age” from the object using the “delete” operator:
Print the object with remaining properties on the console:
It can be observed that the “age” property has been successfully deleted from an object: