I have two arrays. 1 array is an array of distances from a certain point. I know that if I want to sort this by shortest to farthest distance, that is easily done with an array sort. However, my other array is an array of city names that correspond with the distances in the first array. How could I sort the city array such that it would be identical to the distance array order after a numerical sort? Would it be easier to put them both into one array and some how specify to sort only the distance set? I wouldn’t know how to do that. Thanks!

I should have been a little more clear. I was trying to use the array.sort() function rather than writing a sort from scratch

You never write a sort from scratch! Sort gets a comparison function… It can get exotic!

A classic comparison function is

function sortByFirstName(a, b) {
var x = a.FirstName.toLowerCase();
var y = b.FirstName.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

You call it like this:

someArray.sort(sortByFirstName)

The key to writing custom comparison routines is to get the x & y from the other array like

x = otherArray[a];
y = otherArray[b];