// Price Low To High
array?.sort((a, b) => (a.price > b.price ? 1 : -1))
// Price High To Low
array?.sort((a, b) => (a.price > b.price ? -1 : 1))
// Name A to Z
array?.sort((a, b) => (a.name > b.name ? 1 : 1))
// Name Z to A
array?.sort((a, b) => (a.name > b.name ? -1 : 1))
// Sort by date
array.sort((a,b) => new Date(b.date) - new Date(a.date));
//For Ascending
a.sort((a,b)=> (a.name > b.name ? 1 : -1))
//For Descending
a.sort((a,b)=> (a.name < b.name ? 1 : -1))
arr.sort((x, y) => x.distance - y.distance);
myArray.sort(function(a, b) {
return a.distance - b.distance;
});
//Sort Objects in array Descending order
const sortDesc(a,b) => {
return b.timestamp - a.timestamp;
}
//Sort Objects in array Ascending order
const sortAsc(a,b) => {
return a.timestamp - b.timestamp;
}
<Array>.sort(sortAsc);
<Array>.sort(sortDesc);