title: Javascript - access object member when identifier string is stored in a var
body: <p>I've got a pretty simple question (and tentative answers), I just want to see if maybe there is a better answer out there.</p>
  
  <p>How can you access an object member in javascript when the member identifier is stored in another variable? Example:</p>
  
  <pre><code>state = 'sync';
  
  messages = {
    'sync': 'asdf',
    'ready': 'asdf',
    'complete': 'asdf'
  };
  </code></pre>
  
  <p>Possibilities:
    1. message = <code>eval('messages.' + state);</code></p>
  
  <ol start="2">
  <li>turn message into a hash (in prototype or jquery--not sure about jquery) and access through the framework's method</li>
  </ol>
  
  <p>What other ways are there? Anything cleaner? In php it would be simple <code>$message = $messages-&gt;$sync</code>.</p>
  
  <p>I'm sure this question has been answered many times but it is tough to search for... all I get are eval responses when I search for 'variable variables'</p>
  
  <p>Thanks</p>