Setting all Global variables to Null

Hi,

I seem to have a brain cramp. I’m trying to be able to have a global method that will set all global variables to null when called. I could of course name and call them all individually in the method but then I have to remember to add new globals to the method if I add others. I can get their names easily enough by looping through the ‘globals.allvariables’. But where I am screwing myself into an endless mental loop, after ‘shifting’ those global variable names out of that array, being then able to set their value to null. So I have:

var y = globals.allvariables;
for (var i = 0;i < y.length;i++)
{
    var x = y.shift();
    var g_var_name = 'globals.' + x
    
}

Can someone point me in the right direction? I’m stuck. With the ‘name’ of the variable I can set the properties of that variable easily enough (visibility etc.) but I’m all of a sudden lost in setting the VALUE of the variable. Maybe it’s late and I’m sure I’m missing something obvious but any pointers in the right direction would be much appreciated! :?

var y = globals.allvariables

for ( var i = 0 ; i < y.length ; i++ ) {
	globals[y[i]] = null
}

The nested brackets may be a bit confusing. Breaking it apart, you normally assign a global like this:

globals.whatever_global_field = null

This is the same thing:

var y = "whatever_global_field"
globals[y] = null

Variable y in this case is an array of global names so replace y with y*.*

Thanks David! I don’t know whether I had just been working too long or my ancient brain cells are rotting but I was just chasing my tail trying to get it right. So I go home and then I have your answer waiting for me! Thanks a lot.

John

P.S. The really annoying thing is I had something on the SAME solution that I had done a couple of months ago that was very similar but dealing with the text of elements rather than the values of globals and it completely slipped my mind! :oops: