title: Sort a JavaScript array of named objects by numeric named property
body: <p>I've seen multiple similar questions to this, but I can't figure out how to apply the proposed solutions to a slightly different data structure.</p>
  <p>Here's an array of named objects that need to be sorted numerically by the property <code>count</code>:</p>
  <pre><code>const myArray = [
    {ABC:{label:'ABC', count:3}},
    {EFG:{label:'EFG', count:10}},
    {DEF:{label:'DEF', count:9}},
    {FGH:{label:'FGH', count:1}}
  ]
  </code></pre>
  <p>And the resulting array after sorting should be like this:</p>
  <pre><code>myArray = [
     {FGH:{label:'FGH', count:1}},
     {ABC:{label:'ABC', count:3}},
     {DEF:{label:'DEF', count:9}},
     {EFG:{label:'EFG', count:10}}
  ]
  </code></pre>
  <p>If the objects didn't have a name (ABC, DEF, etc) then the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort" rel="nofollow noreferrer">MDN web docs</a> (along with multiple similar questions here) contain the solution for sorting such an array.</p>
  <p>That is, consider a slightly different array of unnamed objects:</p>
  <pre><code>const myArray1 = [
    {label:'ABC', count:3},
    {label:'EFG', count:10},
    {label:'DEF', count:9},
    {label:'FGH', count:1}
  ]
  </code></pre>
  <p>This one-liner works: <code>myArray1.sort((a, b) =&gt; a.count - b.count)</code> to obtain:</p>
  <pre><code>myArray1 = [
    {label:'FGH', count:1},
    {label:'ABC', count:3},
    {label:'DEF', count:9},
    {label:'EFG', count:10}
  ]
  </code></pre>
  <p>I know a more complex function expression is necessary to handle this, but I just don't know the language well enough (yet) to figure it out.</p>