0

Having

x = {a: true, z: false, c: true, x: true, b: false}

I need to obtain the sorted by value object (true first)

xs = {a: true, c: true, x: true, z: false, b: false}

I tried

let x = {a: true, z: false, c: true, x: true, b: false};
console.log ({...Object.entries(x).sort((a, b) => b[1]-a[1])})

but it gives me the zero indexed map... NOK...

serge
  • 13,940
  • 35
  • 121
  • 205
  • Out of curiosity, what difference does it make to you which order the properties of an object are in? Also, Did you try `Object.fromEntries(Object.entries(x).sort((a, b) => b[1] - a[1]))`? – Wyck Oct 08 '22 at 00:18

0 Answers0