title: Sort Array Object with Multiple Keys: Javascript
body: <p>Well, I have an array objects with random values,
  Ex.</p>
  
  <pre><code>var arr = [
      { id:1001, date:"20-02-2014", Name: 'demo1' },
      { id:1004, date:"13-02-2014", Name: 'demo0' },
      { id:1000, date:"10-02-2014", Name: 'demo14' },
      { id:1004, date:"16-02-2014", Name: 'demo10' },
      { id:1006, date:"22-02-2014", Name: 'demo111' },
      { id:1003, date:"28-02-2014", Name: 'demo16' },
      { id:1000, date:"28-01-2014", Name: 'demo12' },
      { id:1004, date:"28-01-2014", Name: 'demo01' },
      { id:1000, date:"08-01-2014", Name: 'demo41' },
      { id:1006, date:"08-01-2014", Name: 'demo91' }
  ]
  </code></pre>
  
  <p>I wanted to sort this array firstly by key <code>id</code> &amp; then by key <code>date</code> as,</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>sorted_arr = [
   {"id":1000,"date":"08-01-2014","Name":"demo41"}, //group1
   {"id":1000,"date":"28-01-2014","Name":"demo12"}, //group1
   {"id":1000,"date":"10-02-2014","Name":"demo14"}, //group1 
   {"id":1001,"date":"20-02-2014","Name":"demo1"},  //group2
   {"id":1003,"date":"28-02-2014","Name":"demo16"}, //group3
   {"id":1004,"date":"28-01-2014","Name":"demo01"}, //group4
   {"id":1004,"date":"13-02-2014","Name":"demo0"},  //group4
   {"id":1004,"date":"16-02-2014","Name":"demo10"}, //group4
   {"id":1006,"date":"08-01-2014","Name":"demo91"}  //group5
   {"id":1006,"date":"22-02-2014","Name":"demo111"} //group5
  ]
  </code></pre>
  
  <p>I tried few generic code to sort,</p>
  
  <pre><code>    // generic comparison function
      cmp = function(x, y){
        return x &gt; y ? 1 : x &lt; y ? -1 : 0; 
      };
  
  
      arr.sort(function(a, b){
         return cmp( 
            [cmp(a.id, b.id), cmp(a.date, b.date)], 
            [cmp(b.id, a.id), cmp(b.date, a.date)]
         );
      });
  </code></pre>
  
  <p>I referred few examples <a href="https://stackoverflow.com/questions/979256/sorting-an-array-of-javascript-objects/979325#979325">SO Example</a> but not getting expected output. Please suggest me best way to get this.</p>