From this site you can use the Haversin formula:
a = sin²(Δφ/2) + cos(φ1).cos(φ2).sin²(Δλ/2) c = 2.atan2(√a, √(1−a)) d = Rc
What can be implemented in Javascript:
var R = 6371;
Then just do it for all cities using the loop and finding the smallest.
source share