Jump to content

unset() equivalent


killboy

Recommended Posts

Hi there.In PHP exists the unset() method; it frees a variable from memory.I want to know if there's any equivalent in JavaScript, so I can do something like:

<script type="text/javascript">function a(){   var k=new Array();   for (i=0;i<k.length;i++)  {	  //Some stuff here   }   unset(k);}

Thanks for the help

Link to comment
Share on other sites

you set the value to null. this example creates an array of three items and prints them to the screen, then an error is generated after we set the array to null

<script type="text/javascript">   var k = ["item1","item2","item3"]   for (var i=0;i<k.length;i++)   {   	document.write(k[i] + "<br>")   }   k = null   for (var i=0;i<k.length;i++) <!-- this will cause an error because k is null -->   {   	document.write(k[i] + "<br>")    }</script>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...