0

How do i sort this object here is my code

const player = {"Bong":"henry","rj":"ken","Robert":"dj","Brad":"jeff" }
Object.entries(player).sort(([k,v]) => {
    if(k < v){
        return -1
    }
    if(k > v){
        return 1
    }
    return 0
})

my Expected output should be:

{"Bong":"dj","Brad":"henry","rj":"jeff","Robert":"ken"}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Scaplog
  • 35
  • 4
  • Does this answer your question? [Sort array of objects according to another object](https://stackoverflow.com/questions/74514272/sort-array-of-objects-according-to-another-object) – Srushti Shah Apr 17 '23 at 04:04
  • @SrushtiShah It's not an array of objects, it's a single object. – Barmar Apr 17 '23 at 04:07
  • There is no point of sorting the object as it can be accessed by keys. You can convert this object to array of objects and then sort it – Srushti Shah Apr 17 '23 at 04:09

0 Answers0