title: Why does document.getElementsByClassName return an array here?
body: <p>Sorry for a stupid question, but maybe someone can explain it to me.  On w3school web-site you can find a modal example. And in order to close the modal they use the following line of code: </p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;span class="close"&gt;&amp;times;&lt;/span&gt;
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>// Get the &lt;span&gt; element that closes the modal
  var span = document.getElementsByClassName("close")[0];
  </code></pre>
  
  <p>Why to use array here? I tried this code without this array and it doesn’t work. I tried to use different indexes in this array and it also doesn’t work. </p>
  
  <p>Why do we use [0] here and how does it exactly work?</p>