- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we remove a property from a JavaScript object? - JavaScript
Let’s say, we have an object as follows −
const myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" };
We are required to illustrate the best way to remove the property regex to end up with new myObject?
Following is the solution −
const myObject = { "ircEvent": "PRIVMSG", "method": "newURI" };
The delete operator is used to remove properties from objects.
const myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; delete myObject['regex']; console.log(myObject.hasOwnProperty("regex")); // false
The delete operator in JavaScript has a different function to that of the keyword in C and C++ −
It does not directly free memory. Instead, its sole purpose is to remove properties from objects.
Output
Following is the console output −
False
- Related Articles
- How do I remove a property from a JavaScript object?
- How to remove a property from a JavaScript object?
- Removing property from a JSON object in JavaScript
- How do I remove a particular element from an array in JavaScript
- Remove number properties from an object JavaScript
- How to create an object property from a variable value in JavaScript?
- Can we check if a property is in an object with JavaScript?
- Iterate over an object and remove false property in JavaScript
- How to remove “,” from a string in JavaScript
- Add a property to a JavaScript object constructor?
- How to remove all blank objects from an Object in JavaScript?
- How to delete a property of an object in JavaScript?
- How do we check if an object is an array in Javascript?
- Merge object & sum a single property in JavaScript
- How can we use a JavaScript function as an object?

Advertisements