WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Remove a Property from a JavaScript Object

Topic: JavaScript / jQueryPrev|Next

Answer: Use the delete Operator

You can use the delete operator to completely remove the properties from the JavaScript object. Deleting is the only way to actually remove a property from an object.

Setting the property to undefined or null only changes the value of the property. It does not remove property from the object. Here's an example:

  • <script>
  •     var person = {
  •         name: "Harry",
  •         age: 16,
  •         gender: "Male"
  •     };
  •     
  •     // Deleting a property completely
  •     delete person.age;
  •     alert(person.age); // Outputs: undefined
  •     console.log(person); // Prints: {name: "Harry", gender: "Male"}
  •     
  •     // Setting the property value to undefined
  •     person.gender = undefined;
  •     alert(person.gender); // Outputs: undefined
  •     console.log(person); // Prints: {name: "Harry", gender: undefined}
  • </script>

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.