title: Treat getElementById return value as array
body: <p>I have a Javascript as follows;</p>
  
  <pre><code>if (document.getElementsByClassName('someClass'))
  {
  obj = document.getElementsByClassName('someClass');
  }
  else if (document.getElementById('someId'))
  {
  obj = document.getElementById('someId');
  }
  </code></pre>
  
  <p>Now there is a for loop which acts on this "obj"</p>
  
  <pre><code>for(i=0; i&lt;obj.length;i++){
  obj[i].addEventListener() // Pseudo code shown here
  } 
  </code></pre>
  
  <p>The issue is this works fine if <code>obj</code> is returned as an array i.e. from <code>document.getElementsByClassName</code>.</p>
  
  <p>But if <code>document.getElementById('someId')</code> is true, it does not return an array and the for loop fails to execute.</p>
  
  <p>How can I fix this issue, given that I cannot do anything to the HTML code itself?</p>
  
  <p>Thank you.</p>