Using variables with nested Javascript object
<p>Suppose I have this:</p>

<pre><code>var a = { A : { AA : 1 }, B : 2 };
</code></pre>

<p>Is there a way for me to create a variable that could allow me to reference either AA or B? What would the syntax look like?</p>

<pre><code>// I know I can do this:    
a['B']; // 2
a['A']['AA']; // 1

// something like this?
var myRef = ???;
a[myRef]; 1 or 2 depending on myRef
</code></pre>

<p>If not, what's a better way to get what I'm going for here?</p>
