delete (Operator/unary)

Property deletion operator.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 3.0
Internet Explorer - 4.0
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera - 3.0
JavaScript syntax:-delete anObject
-delete myArray[anIndex]
-delete myObject.aProperty
Argument list:anIndexThe index of the item to be deleted from the array
anObjectAn object to be deleted
aPropertyAn object property to be removed

The delete operator is used to delete a property from an object or delete a reference to an object. It can also be used to delete an element from an array.

Using the new operator, a new object is created with a reference count of zero. Assigning that object creation to a variable increments the reference count. Saving it as an object property also increments the reference count. Storing it in an array does likewise.

All of these are simply references to the same object.

Deleting a variable containing a reference to an object decrements the reference count for that object.

The associativity is from right to left.

Refer to the operator precedence topic for details of execution order.

Warnings:

Example code:

   // Create a new object

   myObject = new Object;

   // Then delete a reference to it

   delete myObject;

See also:Associativity, Garbage collection, Grouping operator ( ), JSObject.removeMember(), Memory leak, Object object, Operator Precedence, Property attribute, Reference counting, Unary expression, Unary operator, Variable statement

Cross-references:

ECMA 262 edition 2 - section - 11.1.4

ECMA 262 edition 2 - section - 11.4.1

ECMA 262 edition 3 - section - 11.4.1

Wrox Instant JavaScript - page - 21

Wrox Instant JavaScript - page - 28