Visit Mozilla.org

Core JavaScript 1.5 Guide:Creating New Objects:Deleting Properties

From MDC


[edit] Deleting Properties

You can remove a property by using the delete operator. The following code shows how to remove a property.

//Creates a new object, myobj, with two properties, a and b.
myobj = new Object;
myobj.a = 5;
myobj.b = 12;

//Removes the a property, leaving myobj with only the b property.
delete myobj.a;

You can also use delete to delete a global variable if the var keyword was not used to declare the variable:

g = 17;
delete g;

See delete for more information.

« Previous Next »