title: How can I filter a Javascript array and maintain it's indices?
body: <p>Here is what I have currently:</p>
  
  <pre><code>var myArray = [];
  myArray[15] = 2;
  myArray[6323] = 1;
  myArray[349022] = 3;
  myArray = myArray.filter(function(i,v,a){return ! (typeof v == 'undefined')});
  myArray = myArray.sort(function(a,b){return (a - b)});
  </code></pre>
  
  <p>When I console.log() allocationOrder after the "filter" function, I get the values that I expect, but the indices are not maintained. How can I maintain the indices but also remove the undefined values (due to having spread out indices)? Keep in mind that I need to sort the array by value afterwards (which is why I avoided objects as a solution).</p>