killboy Posted March 12, 2008 Share Posted March 12, 2008 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 More sharing options...
aalbetski Posted March 12, 2008 Share Posted March 12, 2008 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 More sharing options...
justsomeguy Posted March 12, 2008 Share Posted March 12, 2008 If you want to delete an object or a property or array element then you can just use the delete operator.http://devguru.com/technologies/javascript/11526.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.