title: How to safely wrap an object into an array in JavaScript
body: <p>I have a function that takes in an <code>Array</code>, iterates over it finding all <code>Objects</code> and displays them to the UI.</p>
  
  <p>In rare cases, I have to supply an <code>Object</code> (result from a <code>WS</code> as <code>application/JSON</code>) which is not an <code>Array</code> by default and hence my function fails to iterate over it and display on the UI.</p>
  
  <p>In normal cases my <code>Array</code> looks like this:</p>
  
  <pre><code>[
    { "name" : "foo"},
    { "name" : "bar"},
    { "name" : "baz"}
  ]
  </code></pre>
  
  <p>and this works like it is supposed to. However, sometimes the data I get could be this:</p>
  
  <pre><code>{ "name" : "I am not in a List"}
  </code></pre>
  
  <p>and my function that takes in an array looks like this:</p>
  
  <pre><code>function loadJSONIntoUI(data) {
  
      for (var aMsg = 0; aMsg &lt; data.length(); aMsg++) {
          // Do something with each `index` in the List
      }
  }
  </code></pre>
  
  <p>Is there a way I can detect that the single object which is not an array is an odd one and probably put it into a List on the fly and pass it to a function?</p>
  
  <p>So far I have tried to use <code>typeof</code> and also tried to create a new <code>Array</code> on the fly and <code>push</code> my object into it but it prints out a <code>1</code> when I do that.</p>