The sort() method needs a compare function for objects. Return negative to sort a before b, positive for b before a.
const users = [
{ name: "Bob", age: 30 },
{ name: "Alice", age: 25 }
];
users.sort((a, b) => a.age - b.age);
// Alice (25) comes before Bob (30)
This sorts by age ascending. Use b.age - a.age for descending.