title: Array.sort not working correctly
body: <p>I need the <code>sort</code> function to sort the dates from the earliest date to the latest date. What can I do to fix this in my tasks table?</p>
  
  <pre><code>var tasks = new Array();
  var index = 0;
  
  function addTask() {
      var temptask = document.getElementById("taskinfo").value;
      var td = document.getElementById("taskdate").value;
      var tempdate = new Date(td);
  
      //add array and populate from tempdate and temptask
      //generate html table from 2d javascript array
      tasks[index] = {
          Date: tempdate,
          Task: temptask,
      };  
  
      index++
  
      tasks.sort(function(a,b){return new Date(b.Date).getTime() - new Date(a.Date).getTime()});
  
      var tablecode = "&lt;table class = 'tasktable'&gt;" +
          "&lt;tr&gt;"+
          "&lt;th&gt;Date&lt;/th&gt;"+
          "&lt;th&gt;Task&lt;/th&gt;"+
          "&lt;/tr&gt;";
      for (var i = 0; i &lt; tasks.length; i++) {
          tablecode = tablecode + "&lt;tr&gt;" +
              "&lt;td&gt;" + tasks[i]["Date"].toDateString() + " &lt;/td&gt;" +
              "&lt;td&gt;" + tasks[i]["Task"] + " &lt;/td&gt;" +
              "&lt;/tr&gt;";
      }
  
      tablecode = tablecode + "&lt;/table&gt;";
  
      document.getElementById("bottomright").innerHTML = tablecode;
  
      return false;
  }
  </code></pre>
  
  <p>I have tried many different syntax variations and can not get the <code>sort</code> function to sort in descending order</p>