Partager via


delete Operator (Windows Scripting - JScript)

 

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

Syntax

delete expression

Remarks

The expression argument is a valid JScript 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

Requirements

Version 3

Change History

Date

History

Reason

September 2009

Added two examples.

Customer feedback.

See Also

Operator Precedence (Windows Scripting - JScript)
Operator Summary (Windows Scripting - JScript)
Objects (Windows Scripting - JScript)
Creating Your Own Objects (Windows Scripting - JScript)
Using Arrays (Windows Scripting - JScript)
Array Object (Windows Scripting - JScript)