Archive for the ‘JavaScript’ Category

How the hay hoo do you ’set’ a var in JavaScript

Friday, August 17th, 2007

I want to ’set’ a var using a dynamic name in JavaScript. Some other programing languages allow you to do this with commands like ‘Set’. You pass it to arguments: 1) the variable name as a string and 2) the value you want to set that variable:

set(’some_var_as_string’, 10);

 This will set the variable some_var_as_string to 10.

But JavaScript has nothing like this and I can find any documentation about it.

My work-around: use Window[’var_name’].

window[’var_name’] = 10

This will set the globale variable var_name to 10.