delete

JavaScript 1.0+, ECMAScript 1.0+, JScript 3.0+ Nav2+, NES3+, IE 4+, Opera Syntax

delete property
						

Description

The delete operator deletes properties from objects and array elements from arrays by making them undefined. Actual memory deallocation is done by JavaScript garbage collection. Some objects, such as variables created by the var statement, are not affected by the delete operator.

Caution

Prior to JavaScript 1.2, the delete operator set the object property to null rather than undefined.

Example

The code in Listing 6.115 demonstrates how to use the delete operator to delete a Date object. Notice that the last document.write() statement does not write anything to the browser because theDate is undefined after using the delete ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.