title: JAVASCRIPT: pass json key's name as parameter, and use the parameter to get the value
body: <p>In javascript, is there a way to treat a JSON keyname as a variable?</p>
  <p>For instance, below I want to perform (any set of actions) on the value of a different key in JSON each time, by telling it which json key to get by feeding the keyname to the function as a parameter.</p>
  <p>The basic idea here is:  Make a function to do (x) no matter what JSON it's given. I just need to tell it what key I want.</p>
  <pre><code>var myObj = {name: &quot;John&quot;, age: 31}; // dataset #1
  var myObj2 = {month: &quot;January&quot;, day: 20}; //dataset #2
  
  function myFunction(jsonName, variableKeyName) {   
  
    var variableKeyValue = jsonName + &quot;.&quot; + variableKeyName;  //wrong way to do this, apparently.
   
    console.log(variableKeyValue); 
  }
  
  myFunction(&quot;myObj&quot;, &quot;name&quot;); //want this to log &quot;John&quot;, not the string &quot;myObj.name&quot;.
  myFunction(&quot;myObj2&quot;, &quot;day&quot;); //want this to log &quot;20&quot;, not the string &quot;myObj2.day&quot;. 
  
  </code></pre>
  <p>Is this possible?  How do get the function to assign the VALUE of the string I'm building with the parameter, rather than just the string as &quot;jsonNameX.variableKeyNameX&quot;?</p>