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