How would you sort this array with these objects by distance, so that you have the objects sorted from smallest distance to biggest distance?
[
{ distance: 3388, duration: "6 mins", from: "Lenchen Ave, Centurion 0046, South Africa" },
{ distance: 13564, duration: "12 mins", from: "Lenchen Ave, Centurion 0046, South Africa" },
{ distance: 4046, duration: "6 mins", from: "Lenchen Ave, Centurion 0046, South Africa" },
{ distance: 11970, duration: "17 mins", from: "Lenchen Ave, Centurion 0046, South Africa" }
]
myarray.sort((a, b) => a.distance - b.distance). To sort lexicographically, usea.from.localeCompare(b.from). To sort descending instead of ascending, negate the return value (e.g.b.distance - a.distanceinstead ofa.distance - b.distance). To sort numeric strings, optionally useNumber. To sort by multiple properties, chain other sorts with||, e.g.b.someNumber - a.someNumber || a.someString.localeCompare(b.someString).