title: Sort an array of objects by hour minutes in ascending order from earliest to latest
body: <p>I have this code to sort an array of objects.  The data in the objects is channel and time (hour, minutes).  I want the sort to be by channels based on time from earliest to latest.</p>
  
  <p>The channel data is accessed in this way:</p>
  
  <pre><code>channel_array[icount].data[0].hour
  channel_array[icount].data[0].minutes
  </code></pre>
  
  <p>That <code>data</code> object array is like this and is already sorted:</p>
  
  <pre><code>[{hour:1, minutes:10},{hour:4, minutes:01}...]
  </code></pre>
  
  <p>Now all I need is to sort the channels from earliest to latest on the first element of the data array <code>{hour:1, minutes: 10}</code>.  I do this with three nested loops.  But this is not ideal.  Is there a better way to do the sorting?</p>
  
  <pre><code>        var current_time = new Date();
          var current_hour = current_time.getHours();
          var comp_hour = current_hour - 1;
          for (var ih = 0; ih &lt; 24; ih++) {
              comp_hour += 1;
              if (comp_hour == 24) { comp_hour = 0; }
              for (var minutes = 0; minutes &lt; 60; minutes++) {
                  for (var icount = 0; icount &lt; channel_array.length; icount++) {
                      if (channel_array[icount].data.length &gt; 0) {
                          var channel_hour = channel_array[icount].data[0].hour;
                          var channel_minutes = channel_array[icount].data[0].minutes;
                          var channel_phase = channel_array[icount].data[0].phase;
                          var next_day = channel_array[icount].data[0].next_day;
                          if (channel_phase.toLowerCase() == "pm" &amp;&amp; channel_hour != 12) { channel_hour += 12; }
                          if ( parseInt(channel_hour) == parseInt(comp_hour) &amp;&amp; parseInt(channel_minutes) == parseInt(minutes) &amp;&amp; next_day != 1 ) {
                              channel_array_sort.push(channel_array[icount]); 
                          }
                      }           
                  }
              }
          }
  </code></pre>