title: Accessing an array element inside JSON Object
body: <p>Unintentionally, In my project I had used the following code and I was surprised to see that is working:</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;span id="output"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>var myObject = {
    'a': '----First---',
    'b': '----Second---',
    'c': '----Third----'
  };
  
  var myArray = ['a'];
  
  // First Case
  output.innerHTML = myObject[myArray];
  
  var myArray2 = ['b'];
  
  // Second Case
  output.innerHTML += myObject[myArray2];
  
  var myArray3 = ['a', 'b'];
  
  // Third Case 
  output.innerHTML += myObject[myArray3];
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>----First-------Second---undefined
  </code></pre>
  
  <p>Jsbin Link: <a href="http://jsbin.com/godilosifu/1/edit?html,js,output" rel="nofollow">http://jsbin.com/godilosifu/1/edit?html,js,output</a></p>
  
  <p>I am directly accessing array reference within Object which should be undefined in all the cases but strangely When array is of Size 1, it always gets the first element and use that as the object key.</p>
  
  <p>I just want to know what is this concept called and why is this happening ?</p>