Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

delete Operator (JavaScript)

Deletes a property from an object, or removes an element from an array.

delete expression

The expression argument is a valid JavaScript expression that usually results in a property name or array element.

If the result of expression is an object, the property specified in expression exists, and the object will not allow it to be deleted, false is returned.

In all other cases, true is returned.

The following example shows how to remove an element from an array.

// Create an array.
var ar = new Array (10, 11, 12, 13, 14);

// Remove an element from the array.
delete ar[1];

// Print the results.
document.write ("element 1: " + ar[1]);
document.write ("<br />");
document.write ("array: " + ar);
// Output:
//  element 1: undefined
//  array: 10,,12,13,14

The following example shows how to delete properties from an object.

// Create an object and add expando properties.
var myObj = new Object();
myObj.name = "Fred";
myObj.count = 42;

// Delete the properties from the object.
delete myObj.name;
delete myObj["count"];

// Print the results.
document.write ("name: " + myObj.name);
document.write ("<br />");
document.write ("count: " + myObj.count);
// Output:
//  name: undefined
//  count: undefined

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.