delete
special operator
JS Home <<
JS Reference <<
delete
Property deletion.
Description
The delete
special operator allows us to delete a property of an object.
Syntax
Signature | Description |
---|---|
delete expression | Special operator which allows us to delete a property of an object. |
Parameters
Parameter | Description |
---|---|
expression | Expression that evaluates to an object reference. |
Returns
Will return false
only when a property exists and cannot be deleted. Will return true
in all other situations, even when the property doesn't exist.
Examples
Following are examples of the delete
special operator.
// The delete operator.
var aVariable = 5;
// Cannot delete aVariable as created using var statement ( returns false)
alert(delete aVariable);
bVariable = 5;
alert(delete bVariable); // Will be deleted ( returns true)
var names = ['fred', 'ned', 'ted', 'jed' ];
alert(delete names[1] + ' Array now holds: ' + names);
Related Tutorials
JavaScript Basic Tutorials - Lesson 7 - Objects