title: How can I sort a javascript array of objects numerically and then alphabetically?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1129216/sorting-objects-in-an-array-by-a-field-value-in-javascript">Sorting objects in an array by a field value in JavaScript</a>  </p>
  </blockquote>
  
  
  
  <p>How can I sort an array of objects numerically (by id) then alphabetically (by name)?</p>
  
  <p>The current way is providing invalid output.</p>
  
  <p>This is the object i'm trying to sort through</p>
  
  <pre><code>var items = [
      {
          "id": 165,
          "name": "a"
      },
      {
          "id": 236,
          "name": "c"
      },
      {
          "id": 376,
          "name": "b"
      },
      {
          "id": 253,
          "name": "f"
      },
      {
          "id": 235,
          "name": "e"
      },
      {
          "id": 24,
          "name": "d"
      },
      {
          "id": 26,
          "name": "d"
      }
  ]
  </code></pre>
  
  <p>and the way i'm trying to sort</p>
  
  <pre><code>items.sort(function(a, b) {
      return (a.id - b.id);
  }).sort(function(a, b) {
      return (a.name - b.name);
  });
  </code></pre>
  
  <p>here is the jsfiddle.</p>
  
  <p><a href="http://jsfiddle.net/jh4xb/" rel="noreferrer">http://jsfiddle.net/jh4xb/</a></p>
  
  <p>EDIT: Sorry for the confusion, I've been so confused by this problem for a while.</p>
  
  <p>What I'm trying to accomplish is to sort by the highest id first, and then sort alphabetically so in the end it should look like:</p>
  
  <pre><code>var items = [
      {
          "id": 376,
          "name": "b"
      },
      {
          "id": 253,
          "name": "f"
      },
      {
          "id": 236,
          "name": "c"
      },
      {
          "id": 235,
          "name": "e"
      },
      {
          "id": 165,
          "name": "a"
      },
      {
          "id": 26,
          "name": "d"
      },
      {
          "id": 24,
          "name": "d"
      }
  ]
  </code></pre>