As far as i know you can't really sort an object.
However, you can log all of your existing distances and then based on distance count, filter the array in a for loop. In order to avoid logging the same distance if you have the same distance in 2 objects you'd need a unique identificator on each set (like the name) to identify it by and remove it from the array, I've added such a process in my example which is why i added object D.
When using multiple distances you can detect this via string.includes("km") and just multiply distances that contain the trigger "km". Which means you'd have to parse the numbers first since you supply them as string.
let my = {
array: [
{
distance: "4 km",
name: 'A',
AmountDue: 58576,
OrderValue: 0,
Visited: ""
},
{
distance: "10.3 km",
name: 'B',
AmountDue: 58576,
OrderValue: 0,
Visited: ""
},
{
distance: "8 km",
name: 'C',
AmountDue: 58576,
OrderValue: 0,
Visited: ""
},
{
distance: "8 km",
name: 'D',
AmountDue: 12346,
OrderValue: 0,
Visited: ""
}]
}
console.log(my.array)
sorter(my)
function sorter(my)
{
array = my.array;
distances = []
for (i = 0; i < array.length; i++)
{
distances.push(array[i].distance.split(" ")[0])
}
distances.sort(function(a, b)
{
return a - b
});
newarray = []
for (i = 0; i < distances.length; i++)
{
newarray.push(array.filter(e => e.distance.split(" ")[0] == distances[i])[0])
array = array.filter(f => f.name != array.filter(e => e.distance.split(" ")[0] == distances[i])[0].name)
}
console.log(newarray)
}