

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Removing property from a JSON object in JavaScript
Let’s say, we create 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 as follows −
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 Questions & Answers
- Create array from JSON object JavaScript
- From JSON object to an array in JavaScript
- Sorting a JSON object in JavaScript
- Flattening a JSON object in JavaScript
- Constructing a nested JSON object in JavaScript
- JSON group object in JavaScript
- How to construct a JSON object from a subset of another JSON object in Java?
- How to remove a property from a JavaScript object
- How to remove a property from a JavaScript object?
- How do we remove a property from a JavaScript object? - JavaScript
- Get value for key from nested JSON object in JavaScript
- Deep Search JSON Object JavaScript
- How do I remove a property from a JavaScript object?
- Print JSON nested object in JavaScript?
- Removing punctuations from a string using JavaScript
Advertisements