Enea Xharja

Sort Object by property

Sort Object by property using JavaScript:

const topScorers = {
  Ronaldo: 770,
  Bican: 805,
  Pele: 767,
};

const playersSorted = Object.keys(topScorers).sort(
  (a, b) => topScorers[b] - topScorers[a]
);

console.log(playersSorted); // ["Bican", "Ronaldo", "Pele"]

Updated on March 19, 2021

Tagged with: javascript, snippets


Profile picture

Hey there! I'm Enea, a web developer currently working at eqolot. Welcome to my little corner of the web, where I share my open collection of notes, code snippets, and resources on topics that interest me.

© 2021 Enea Xharja