title: jQuery - $.each loop through variable object
body: <p>I'm working with a JSON dataset that has multiple high level objects. If I literally declare the object name, I can loop through the JSON with no trouble, but when I use a variable in its place, I get errors. It appears that it's trying to apply the variable name as the literal name of the object. Here's a quick example</p>
  
  <pre><code>function(data){
      var select = $('#lists select');
      var activeList = $(select+':selected').val();
  
      $.each(data.activeList, function(i,item){
        // Do stuff    
      });
  }
  </code></pre>
  
  <p>How do I get it to use the value of activeList in this case? To be clear, the variable activeList correctly returns the value of the selected option. If the value of activeList is "Christmas_List", looping through data.activeList should loop through the Christmas_List object within the JSON data. This doesn't work, it appears that data.activeList is looking for the "activeList" object. If I try a literal value in activeList's place (Christmas_List), the loop works properly.</p>
  
  <p>Any ideas? Thanks</p>