Use delete operator to delete properties or array elements in JavaScript

Description

The following code shows how to use delete operator to delete properties or array elements.

Example


<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
theDate = new Date();<!--from  w  w w.j  a va  2s  .com-->
document.write("theDate=",theDate,"<br>Deleting theDate!<br>");

delete theDate;
document.write("theDate=",theDate);   //theDate is undefined
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use delete operator to delete properties or array elements in JavaScript