title: Javascript - use string as object reference
body: <p>If I have a bunch of objects, and within these objects is the string "id" (which is the same as the object name) how can I use this string to reference the object?</p>
  
  <p>Example:</p>
  
  <pre><code>//These objects are tests - note the id's are the same as the object name
  
  var test1 = {
      id : "test1",
      data : "Test 1 test 1 test 1"
  }
  
  var test2 = {
      id : "test2",
      data : "Test 2 test 2 test 2"
  }
  
  
  /* ----- My Function   ----- */
  
  var myObj = null;
  
  function setMyObj(obj){
     myObj = obj;
  }
  
  setMyObj(test1);
  
  /* ----- My Function   ----- */
  </code></pre>
  
  <p>Now, if I call the following:</p>
  
  <pre><code>myObj.id;
  </code></pre>
  
  <p>The Result is "test1" (a string).
  If I want to use this to get the data from test1, how would I do so?</p>
  
  <pre><code>"myObj.id".data
  [myObj.id].data
  </code></pre>
  
  <p>^^^ </p>
  
  <p>These don't work!</p>
  
  <p>Cheers,
  Rich</p>