2
I can sort a simple list using the method sort
Behold:
var distances = [15, 18, 27, 29, 5, 3]
distances.sort(function(a, b){
return a-b;
});
console.log(distances);
But I would like to sort a list of objects based on the attribute distance
, for example:
var listDistances = [
{distance: 857, location: {lat: 15.246, lnt:16.4552}},
{distance: 26, location: {lat: 18.246, lnt:16.4552}},
{distance: 740, location: {lat: 15.246, lnt:16.4552}}
];
This way the result would be:
var listDistances = [
{distance: 26, location: {lat: 18.246, lnt:16.4552}},
{distance: 740, location: {lat: 15.246, lnt:16.4552}},
{distance: 857, location: {lat: 15.246, lnt:16.4552}},
];
How to sort object array by checking the attribute distance
?
Jesus, I think I’d done something wrong then! Vlw... now it’s gone! =)
– viana