How to sort array of objects in descending order in JavaScript

Arrays
By Jad Joubran · 
Last updated Aug 16, 2020
const users = [
  { name: "user1", age: 28 },
  { name: "user2", age: 21 },
  { name: "user3", age: 38 },
  { name: "user4", age: 18 }
];

users.sort((user1, user2) => user2.age - user1.age);

console.log(users);
[
  { name: "user3", age: 38 },
  { name: "user1", age: 28 },
  { name: "user2", age: 21 },
  { name: "user4", age: 18 }
]
Array.sort on MDN