title: Concatenating chosen random property to object to get the array?
body: <p>I have an object with a few arrays in it. I am trying to return one of the arrays randomly. I have a function that returns one of the properties in the object, but I am not sure how to use it when concatenating it to the object name. For example:</p>
  
  <p>Object:</p>
  
  <pre><code>var myObj = {
      itemOne:['blue','red','green'],
      itemTwo:['sky','grass','book'],
      itemThree:['day','month','year']
  } 
  </code></pre>
  
  <p>To get a certain array I would do <code>myObj.itemOne</code> which will return the first array. But I want to randomly return an array. I have a function that will return <code>itemOne</code>, <code>itemTwo</code>, or <code>itemThree</code> randomly, but when concatenating what the function returns with <code>myObj.</code> it does not work. What can I do. Here is the function:</p>
  
  <pre><code>function pickRandomProperty(myObj) {
      var result;
      var count = 0;
      for (var prop in myObj){
          if (Math.random() &lt; 1/++count){
             result = prop;
          }
      }
      return result;
  }
  
  var getItemInObject = pickRandomProperty(myObj);
  </code></pre>
  
  <p>Using what <code>getItemInObject</code> returns, I try to concatenate it with myObj to return the array. How would I do that? Here is what I have tried:</p>
  
  <pre><code>var getItemInObject = pickRandomProperty(myObj);
  var randProp = myObj.getItemInObject;
  </code></pre>
  
  <p>or even:</p>
  
  <pre><code>var randWord = myObj + '.' + getItemInObject;
  </code></pre>
  
  <p>Which returns '[object Object].itemTwo'</p>
  
  <p>Here is a fiddle: <a href="http://jsfiddle.net/xrk7b4zs/" rel="nofollow">http://jsfiddle.net/xrk7b4zs/</a></p>
  
  <p>Thanks for any help</p>