title: JavaScript: find pairs from an object (not array) - collision detection
body: <p>I am building a game using Javascript and I need to do collision detection.</p>
  
  <p>Everything drawn in the game has its own ID and stored in an object.
  I chose to use an object despite an array as a container because it is easy to delete children from it. When for example, a bullet hits a ship, it is removed from the object. But for an array, all of the children have to be shifted when one object is deleted. And it is nice to have IDs to keep track of everything.</p>
  
  <p>In order to find pairs in an array, I can do this:</p>
  
  <pre><code>var a = [];
  //Object container
  
  for(var i = 0; i &lt; a.lenght; i++){
      for(var j = i+1; j &lt; a.lenght; j++){
          var object1 = a[i];
          var object2 = a[j];
          //collision detection
      }
  }
  </code></pre>
  
  <p>But for an object</p>
  
  <pre><code>var o = {};
  //Object container
  
  var progress = [];
  
  for(var key1 in o){
      progress.push(key1);
      for(var key2 in o){
          if(progress.indexOf(key2) === -1){
              var object1 = a[i];
              var object2 = a[j];
              //collision detection
          }
      }
  }
  progress = [];
  </code></pre>
  
  <p>This is a lot uglier than the array. Is there a better way?</p>