Using a string as an object reference
<p>I currently have a Javascript function that uses a string to reference an object name and acces its properties. I'm currently using eval() to get the the desired effect which I know is very, very wrong. Here is an example of how I'm currently achieving what I want:</p>

<pre><code>var stringToObjectRef = function() {

    var myTestVar = "myTestObject";
    var myTestObject = { 'item1' : 100, 'item2' : 12, 'item4' : 18 };

    var myValue = eval(myTestVar + '.item1');

    alert(myValue);

}();
</code></pre>

<p>I've tried using something like [myTestVar].item1, but this returns undefined. What is the correct syntax to achieve this?</p>

<p>Thanks in advance.</p>
