delete special operatorS2C Home « Operators « delete

Property deletion.

Description

The delete special operator allows us to delete a property of an object.

Syntax

Signature Description
delete expressionSpecial operator which allows us to delete a property of an object.

Parameters

Parameter Description
expressionExpression that evaluates to an object reference.
  • Can be a variable name if the variable has been declared as a property of the global object (without var or function statements).
  • An object expression such as someObject.property or someObject['property'].
  • An array-like object expression such as someObject[indexToDelete].

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);  

Press the button below to action the above code:


Related Tutorials

JavaScript Basic Tutorials - Lesson 7 - Objects

go to home page Homepage go to top of page Top