title: Sorting javascript array by first key value
body: <p>I am working on a small project and have ran into a dilemma that may be easy for some people to solve. I am need to sort an array that contains a float value of a distance from point A to point B and a string of an Address. If I have the array without a string in it the array will sort fine using the <code>array.sort(function(a,b){return a-b})</code> but when I add the string value it does not sort correctly. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          var data = &lt;?php echo json_encode($corodinates); ?&gt;;
          var nearest = new Array();
          for (var i = 0; i &lt; 420; i++)
          {
              var markers = [(data.Latitude[i]), (data.Longitude[i])];
              var userLocation = new google.maps.LatLng(42.4999923706, -96.4003067017);
              var dealerLocation = new google.maps.LatLng(markers[0], markers[1]);
              var distance = google.maps.geometry.spherical.computeDistanceBetween(userLocation, dealerLocation);
                  nearest[i] = [(distance/1609.344), (data.Address[i])];
          }       
  
          nearest.sort(function(a,b){return a-b});
      &lt;/script&gt;
  </code></pre>
  
  <p>This is what my array looks like:</p>
  
  <pre><code>0: 482.5813729353341
  1: "10940 S Parker Road #723"
  </code></pre>
  
  <p>I need it to sort by the float value in the 0 key.</p>