title: Javascript sort an array of objects based on numeric key
body: <p>I have an array of objects that looks like this:</p>
  
  <pre><code>var data = [
   {
     title: 'Shirt',
     position: 3
   },
   {
     title: 'Ball',
     position: 1,
   }
  ]
  </code></pre>
  
  <p>How could I sort it for use in a <code>for loop</code> like this.</p>
  
  <pre><code>for(var i in data) {
  
  }
  </code></pre>
  
  <p>I tried:</p>
  
  <p><code>for(var i in data | orderBy:'position')</code></p>
  
  <p>But that is angular so normal Javascript it doesn't work.</p>
  
  <p>I'm thinking their must be some way to sort the array before looping through it, or adding a filter to the loop, not sure which is the best way.</p>