Remoe a property from a JavaScript object
Question
Suppose I have the following JavaScript:
var obj = {
"one": 1,
"two": 2,
"three": 3
};
What is the best way to remove the property two
to end up with the following obj
:
var obj = {
"one": 1,
"three": 3
};
Answer
To delete a property from a JavaScript object, you can use one of them.
delete obj.two;
// or,
delete obj['two'];
// or,
var prop = "two";
delete obj[prop];
References & Resources
- N/A
Latest Post
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- Combine JavaScript and CSS
- Inline Small JavaScript and CSS
- Minify JavaScript and CSS
- Defer Parsing of JavaScript
- Prefer Async Script Loading
- Components, Bootstrap and DOM
- What is HEAD in git?
- Show the changes in Git.
- What is AngularJS 2?
- Confidence Interval for a Population Mean
- Accuracy vs. Precision
- Sampling Distribution
- Working with the Normal Distribution
- Standardized score - Z score
- Percentile
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync