title: Date object doesn't exist after definition?
body: <p>I'm trying to make a function that returns an array of dates in between two dates. This is my code:</p>
  
  <pre><code>Date.prototype.addDays = function(days) 
          {
              var date = new Date(this.valueOf());
              date.setDate(date.getDate() + days);
              return date;
          }
  
  
  function getdaterange(startdate, enddate)
          {
              var s = new Date(startdate);
              var e = new Date(enddate);
              var datearray = [s];
  
              var done = false;
              while(!done)
              {
                  var date = datearray.pop().addDays(1);
                  if (date == e)
                  {
                      datearray.push(date);
                      done = true;
                  }                     
              }
          }
  
  getdaterange("2018-09-01", "2018-09-25");
  </code></pre>
  
  <p>The function isn't done yet, but when I try to manipulate the date object on the line that sets the variable "date", it comes back as undefined or says that .pop() isn't a method of Date. I've tried several different configurations. (Where I change how I am manipulating the date object. For example: defining the variable and then calling the .addDays() method afterwards.) </p>
  
  <p>This is just one of them. Does anybody know whats going on?</p>
  
  <p><strong>Thanks for any help in advanced.</strong></p>
  
  <p><strong>Thanks for your help from the comments. Edited Code:</strong></p>
  
  <pre><code>Date.prototype.addDays = function(days) 
  {
  var date = new Date(this.valueOf());
  date.setDate(date.getDate() + days);
  return date;
  } 
  
  function getdaterange(startdate, enddate)
          {
              var s = new Date(startdate);
              var e = new Date(enddate);
              var datearray = [s];
  
              var done = false;
              while(!done)
              {
                  var temp = datearray;
                  var date = temp.pop().addDays(1);
  
                  if (date.valueOf() == e.valueOf())
                  {
                      datearray.push(date);
                      done = true;
                  }
                  else
                  {
                      datearray.push(date);
                  }      
              }
            return datearray;
          }
          console.log(getdaterange("2018-09-01", "2018-09-25"));
  </code></pre>