title: D3JS dynamically accessing elements of an Array
body: <p>I have a problem when trying to reference an array in a dynamic way. I won't always know before hand which field my user will select so I want to make a dynamic selection into the array. I was hoping I could store the field in a variable, and then use this variable to specify which field I want from the array.</p>
  
  <p>I have made a simple example to illustrate my problem.</p>
  
  <p>If I access the array like this:</p>
  
  <pre><code>console.log('static: ' + nested_data[0].values[0].cat); 
  </code></pre>
  
  <p>Then in returns 'a' which is what I expected, however if I do:</p>
  
  <pre><code>console.log('dynamic :' + nested_data[0].values[0].label); 
  </code></pre>
  
  <p>where label is a variable, then I get 'undefined'. </p>
  
  <p>Anyone know what I'm doing wrong.</p>
  
  <pre><code>// Some Sample data
  var data = [
  { value: 01, cat:'a'},
  { value: 40, cat:'a'},
  { value: 80, cat:'b'},
  { value: 120, cat:'b'}
  ];
  
  //Nest the data on 'cat'
  var nested_data = d3.nest()
  .key(function(d) { return d.cat; })
  .entries(data);
  
  //Print the value of the data[0].values[0].cat
  console.log('static: ' + nested_data[0].values[0].cat); 
  
  //Dynamic, create a variable to hold the parameter I want to refrence
  var label = 'cat';
  //Pass the variable to the array
  console.log('dynamic :' + nested_data[0].values[0].label); 
  </code></pre>