title: Difference between var = {} and var = []?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/688097/objects-vs-arrays-in-javascript-for-key-value-pairs">Objects vs arrays in Javascript for key/value pairs</a>  </p>
  </blockquote>
  
  
  
  <p>I have a variable in JavaScript which I am using like a <em>hash</em>. I can initialize it like:</p>
  
  <pre><code>var selected = [];
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var selected = {};
  </code></pre>
  
  <p>and it does the same exact thing. I'm using it like this for example:</p>
  
  <pre><code>selected["one"] = 1;
  
  if (selected["one"] == 1) console.log("one is selected"); 
  // result: one is selected
  
  if (selected["two"] != 1) console.log("two is not selected");
  // result: two is not selected
  
  selected["one"] = 0;
  
  if (selected["one"] != 1) console.log("one is no longer selected");
  // result: one is no longer selected
  </code></pre>
  
  <p>Is there really a difference? Is one an <em>object</em> and the other an <em>array</em> ? If so, when should I expect to run into problems. Ie., what is the difference between the two in their usage, and why would you chose one over the other?</p>