How to Remove a Property From an Object in JavaScript

How to Remove a Property From an Object in JavaScript

An object is a dynamic collection of key-value pairs. Here is such an object.

const dto = {
message : 'Hi',
priority: 1
}

A property can be deleted using the delete operator.

When the property key is a valid identifier we can use the dot notation to access and delete the property.

delete dto.priority;console.log(dto);
//{message: "Hi"}

When the key is stored in a variable we can use the bracket notation to access and delete the property. Consider t...

 •  0 comments  •  flag
Share on Twitter
Published on April 19, 2021 03:46
No comments have been added yet.