title: Javascript Array Key Lookup
body: <p>I'm sorry if this has been asked before, it's something that's difficult to search for...</p>
  
  <p>I want to use a javascript Array to hold objects, with the key as the ID</p>
  
  <p>for example, let's say I had a bunch of people who had different IDs</p>
  
  <pre><code> var people = new Array();
   var person = {property: value}; // this is person ID 4
  
   var people[4] = person;
  </code></pre>
  
  <p>I want to be able to then reference that user by saying, people[ID].propery</p>
  
  <p>The problem is that the output of this array now would be;</p>
  
  <pre><code> null,null,null,null,object
  </code></pre>
  
  <p>Because it's expecting the keys to be 0,1,2,3,4</p>
  
  <p>Am I being stupid or something? :-)   We can do it for strings right, so why not non-sequential numbers?</p>
  
  <p>What I'm trying to avoid is having to loop over every single object in the array every time I want to access a particular person inside it, therefore I figured that using the ID number as the key would work</p>
  
  <p>Thanks guys! :-)</p>