Remove a property from JavaScript object
Objects in JavaScript can be thought of as maps between keys and values. The delete operator is used to remove these keys, more commonly known as object properties, one at a time. This operator deletes both the value of the property and the property itself also after deletion, the property you cannot be used before it is added back again.
let myObject = {
"Product": "Product - 1",
"Description": "Description - 1",
"Price": "Price 1",
};
delete myObject.Price;
console.log(myObject);
Output:
{ Product: 'Product - 1', Description: 'Description - 1' }
Also, you can use:
delete myObject['Price'];
It is important to note that the delete operator does not directly free memory, and it differs from simply assigning the value of null or undefined to a property, in that the property itself is removed from the object. If the value of a deleted property was a reference type , and another part of your code still holds a reference to that object, then that object will, of course, not be garbage collected until all references to it have disappeared.

Using object destructuring
Object destructuring is an ECMAScript 6 feature. The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
let myObject = {
"Product": "Product - 1",
"Description": "Description - 1",
"Price": "Price 1",
};
const {Price, ...newObj} = myObject;
console.log(newObj); // has no 'Price' key
console.log("\n myObject Remains unchanged..... \n");
console.log(myObject);
Output:
{ Product: 'Product - 1', Description: 'Description - 1' }
myObject Remains unchanged.....
{
Product: 'Product - 1',
Description: 'Description - 1',
Price: 'Price 1'
}
The parentheses ( ... ) around the assignment statement are required when using object literal destructuring assignment without a declaration.
Related Topics
- JavaScript Popup Boxes
- Opening a new window in JavaScript
- How to Create Drop-Down Lists in JavaScript
- How do I include a JavaScript file in another JavaScript file?
- Print the content of a Div using JavaScript/jQuery
- How to get the current URL using JavaScript ?
- How to Detect a Mobile Device with JavaScript/jQuery
- How to validate an email address in JavaScript
- JavaScript Array Iteration
- How to Remove a Specific Item from an Array in JavaScript
- What is JavaScript closures?
- How to get selected value from Dropdown list in JavaScript
- How do I get the current date in JavaScript?
- How to Open URL in New Tab | JavaScript
- How to delay/wait/Sleep in code execution | JavaScript
- How to round to at most 2 decimal places | JavaScript
- How to convert string to boolean | JavaScript
- How to check undefined in JavaScript?
- How To Copy to Clipboard | JavaScript
- How to encode a URL using JavaScript?
- How to force Input field to enter numbers only | JavaScript
- How to create multiline string in JavaScript
- How to Check for an Empty String in JavaScript?