title: Javascript: Sorting Objects (not arrays) in descending
body: <p>I know objects are by default sorted out in ascending order or the way we will insert but I need the best way to sort the object in descending order. Ex:</p>
  
  <pre><code>Input x = {
    a: {},
    b: {},
    c: {},
    d: {}
  }
  
  Output: x = {
    d: {},
    c: {},
    b: {},
    a: {}
  }
  </code></pre>
  
  <p>I tried the below solution, It works but is it a good practice or can I get anything better on this?</p>
  
  <pre><code>x= Object.keys(x).sort().reverse().reduce((obj, key) =&gt; {
      obj[key] = x[key]
      return obj
  }, {})
  </code></pre>