Deletes a property from an object, or removes an element from an array.
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; // Print the results. document.write ("element 1: " + ar); 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, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Windows Store apps. See Version Information.