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 at wohnvoll in Berlin. Welcome to my little corner of the web, where I share my personal collection of notes, code snippets, and resources on topics that interest me.

© 2022 Enea Xharja