Q:

How to find JavaScript variable by its name

Is there a way to find JavaScript variable on the page (get it as an object) by its name? Variable name is available as a string constant.

A:

<script>
var a ="test";
alert(a);
alert(window["a"]);
alert(eval("a"));
</script>

A:

All JS objects (which variables are) are available within their scope as named properties of their parent object. Where no explicit parent exists, it is implicitly the window object.
i.e.:
var x = 'abc';
alert(window['x']); //displays 'abc'

and for a complex object:
var x = {y:'abc'};
alert(x['y']); //displays 'abc'

and this can be chained:
var x = {y:'abc'};
alert(window['x']['y']); //displays 'abc'

A:

If you are wanting a variable that is declared in the global context, it is attached to the window object.  ex: window["variableName"].  All variables are a hash table value within their scope.
If you have to use dotted notation, then you will want to follow kennebec's suggestion, to navigate through the object hierarchy.  eval() can work as well, but is a more expensive operation than is probably needed.

