How to get date range using moment.js

I know this is an old/answered question, but since it's at the top of google here is how to achieve a date range with only moment (and without moment-range):

import moment from 'moment'

/**
 * @param {date|moment} start The start date
 * @param {date|moment} end The end date
 * @param {string} type The range type. eg: 'days', 'hours' etc
 */
function getRange(startDate, endDate, type) {
  let fromDate = moment(startDate)
  let toDate = moment(endDate)
  let diff = toDate.diff(fromDate, type)
  let range = []
  for (let i = 0; i < diff; i++) {
    range.push(moment(startDate).add(i, type))
  }
  return range
}

Returns an array of every "type" (month/day/hour etc) between the two, exclusive of the end date

Example:

let range = getRange('2019-01-01', '2019-01-05', 'days')
// moment dates -> [ '2019-01-01', '2019-01-02', '2019-01-03', '2019-01-04' ]

To get rest of the dates between two dates, you can refer this code-

$scope.dateArr = []; //Array where rest of the dates will be stored

$scope.prevDate = moment().subtract(15, 'days');//15 days back date from today(This is the from date)

$scope.nextDate = moment().add(15, 'days');//Date after 15 days from today (This is the end date)

//extracting date from objects in MM-DD-YYYY format
$scope.prevDate = moment($scope.prevDate._d).format('MM-DD-YYYY');
$scope.nextDate = moment($scope.nextDate._d).format('MM-DD-YYYY');

//creating JS date objects
var start = new Date($scope.prevDate);
var end = new Date($scope.nextDate);

//Logic for getting rest of the dates between two dates("FromDate" to "EndDate")
while(start < end){
   $scope.dateArr.push(moment(start).format('ddd DD-MM'));
   var newDate = start.setDate(start.getDate() + 1);
   start = new Date(newDate);  
}

console.log('Dates:- ');
console.log($scope.dateArr);

This is the console log:-

["Tue 24-05", "Wed 25-05", "Thu 26-05", "Fri 27-05", "Sat 28-05", "Sun 29-05", "Mon 30-05", "Tue 31-05", "Wed 01-06", "Thu 02-06", "Fri 03-06", "Sat 04-06", "Sun 05-06", "Mon 06-06", "Tue 07-06", "Wed 08-06", "Thu 09-06", "Fri 10-06", "Sat 11-06", "Sun 12-06", "Mon 13-06", "Tue 14-06", "Wed 15-06", "Thu 16-06", "Fri 17-06", "Sat 18-06", "Sun 19-06", "Mon 20-06", "Tue 21-06", "Wed 22-06"]