You're not sorting the array of locations, only the array of distances.
You should drop the distance into the locations
array (i.e. as the fourth member of each element):
for(var i = 0; i < locations.length; ++i) {
var l = locations[i];
l[3] = haversine(userLatitude, userLongitude, l[1], l[2]);
}
and then use a "comparator" function that looks at that distance field:
locations.sort(function(a, b) {
return (a[3] < b[3]) ? -1 : ((a[3] > b[3]) ? 1 : 0);
});