Open this example in the interactive library
Source code
const items = [
{ name: "Gamma", rank: 3 },
{ name: "Alpha", rank: 1 },
];
console.log(items.toSorted((a, b) => a.rank - b.rank));
Sample output
[ { name: 'Alpha', rank: 1 }, { name: 'Gamma', rank: 3 } ]