title: How best to do a JavaScript array with non-consecutive indexes?
body: <p>I'm writing a Google Chrome extension, in JavaScript, and I want to use an array to store a bunch of objects, but I want the indexes to be specific <em>non-consecutive</em> ID numbers. </p>
  
  <p>(This is because I need to be able to efficiently look up the values later, using an ID number that comes from another source outside my control.)</p>
  
  <p>For example:</p>
  
  <pre><code>var myObjects = [] ;
  
  myObjects[471] = {foo: "bar"} ;
  
  myObjects[3119] = {hello: "goodbye"}
  </code></pre>
  
  <p>When I do <code>console.log(myObjects)</code>, in the console I see the entire array printed out, with all the thousands of 'missing' indexes showing <code>undefined</code>.</p>
  
  <p>My question is: does this matter? Is this wasting any memory?</p>
  
  <p>And even if it's not wasting memory, surely whenever I loop over the array, it wastes CPU if I have to manually skip over every missing value?</p>
  
  <p>I tried using an object instead of an array, but it seems you can't use numbers as object keys. I'm hoping there's a better way to achieve this? </p>