<p>In Javascript, I have an object:</p>

<pre><code>obj = { one: "foo", two: "bar" };
</code></pre>

<p>Now, I want do do this</p>

<pre><code>var a = 'two';
if(confirm('Do you want One'))
{
  a = 'one';
}

alert(obj.a);
</code></pre>

<p>But of course it doesn't work.  What would be the correct way of referencing this object dynamically?</p>

Like this:
```
```
obj[a]
```
```