How to Select Min/Max Dates in an Array Using JavaScript? Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Here are the different ways to select min/max dates in an array using JavaScript1. Using Math.max and Math.minUse Math.max and Math.min function to get the maximum and minimum dates respectively. JavaScript let dates = [ new Date("2019/06/25"), new Date("2019/06/26"), new Date("2019/06/27"), new Date("2019/06/28") ]; function fun() { const maxDate = new Date(Math.max(...dates)); const minDate = new Date(Math.min(...dates)); console.log("Max date is - " + maxDate); console.log("Min date is - " + minDate); } fun(); OutputMax date is - Fri Jun 28 2019 00:00:00 GMT+0000 (Coordinated Universal Time) Min date is - Tue Jun 25 2019 00:00:00 GMT+0000 (Coordinated Universal Time) In this example: The code finds the maximum (latest) and minimum (earliest) dates from an array of Date objects. It uses Math.max() and Math.min() with the spread operator (...) to get the highest and lowest timestamps, and then converts them back to Date objects. The result is printed using console.log().2. Using reduce() methodUse reduce() method in an array of dates and define the respective function for the maximum and minimum dates. JavaScript let dates = [ new Date("2019/06/25"), new Date("2019/06/26"), new Date("2019/06/27"), new Date("2019/06/28") ]; function fun() { const minDate = dates.reduce((a, b) => (a < b ? a : b)); const maxDate = dates.reduce((a, b) => (a > b ? a : b)); console.log("Max date is - " + maxDate); console.log("Min date is - " + minDate); } fun(); OutputMax date is - Fri Jun 28 2019 00:00:00 GMT+0000 (Coordinated Universal Time) Min date is - Tue Jun 25 2019 00:00:00 GMT+0000 (Coordinated Universal Time) In this example: The code uses reduce() to iterate through the dates array, comparing two dates (a and b) at a time. It finds:Minimum date (minDate): By keeping the smaller of a and b.Maximum date (maxDate): By keeping the larger of a and b.3. Using Spread OperatorTo select the minimum and maximum dates in an array, use the spread operator to clone the array. JavaScript let dates = [new Date('2022-01-01'), new Date('2022-03-15'), new Date('2022-02-10')]; let minDate = new Date(Math.min(...dates)); let maxDate = new Date(Math.max(...dates)); console.log(minDate); console.log(maxDate); Output2022-01-01T00:00:00.000Z 2022-03-15T00:00:00.000Z In this example: The code finds the minimum and maximum dates in an array of Date objects using Math.min() and Math.max().Math.min(...dates): Finds the earliest date by spreading the dates array and comparing their timestamps.Math.max(...dates): Finds the latest date similarly.Converts the timestamps back to Date objects with new Date(). 4. Using Array.prototype.sort with a custom comparatorUsing Array.prototype.sort() with a custom comparator allows you to sort an array based on specific criteria by defining a comparison function. JavaScript let dates = [ new Date("2024-05-15"), new Date("2024-05-17"), new Date("2024-05-13"), new Date("2024-05-20"), ]; dates.sort((a, b) => a - b); let minDate = dates[0]; let maxDate = dates[dates.length - 1]; console.log("Min date:", minDate.toDateString()); console.log("Max date:", maxDate.toDateString()); OutputMin date: Mon May 13 2024 Max date: Mon May 20 2024 In this exampledates[0]: Gives the earliest (minimum) date.dates[dates.length - 1]: Gives the latest (maximum) date.The results are printed in a human-readable format using toDateString(). Comment More infoAdvertise with us Next Article How to get the first and last date of current month using JavaScript ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Questions +1 More Similar Reads Find the min/max element of an Array using JavaScript To find the minimum or maximum element in a JavaScript array, use Math.min or Math.max with the spread operator.JavaScript offers several methods to achieve this, each with its advantages.Using Math.min() and Math.max() Methods The Math object's Math.min() and Math.max() methods are static methods t 2 min read How to Sort a Multidimensional Array in JavaScript by Date ? Sorting a Multidimensional Array by date consists of ordering the inner arrays based on the date values. This needs to be done by converting the date representation into the proper comparable formats and then applying the sorting function to sort the array in ascending or descending order. Below are 2 min read Max/Min value of an attribute in an array of objects in JavaScript In this article, we are given an array of objects and the task is to get the maximum and minimum values from the array of objects. For this approach, we have a few methods that will be discussed below. Methods to get Min/Max values:using JavaScript apply() and Array map()using JavaScript Array reduc 3 min read How to get the first and last date of current month using JavaScript ? Given a month and the task is to determine the first and last day of that month in proper format using JavaScript. JavaScript getDate() Method: This method returns the day of the month (from 1 to 31) for the defined date. Syntax: Date.getDate() Parameters: This method does not accept any parameters. 3 min read How to remove time from date using JavaScript ? Given a Date Object and the task is to remove the time portion from the object using JavaScript. JavaScript split() Method: This method is used to split a string into an array of substrings, and returns the new array. Syntax: string.split( separator, limit ) Parameters: separator: This parameter is 2 min read How to get the month name from Date using JavaScript ? The purpose of this article is to get the month name from a particular date using JavaScript getMonth() method. This method is used to fetch the month(0 to 11) from the given Date object. It returns an integer value ranging from (0 to 11) Zero (0) means January, 1 means February, and so on, till 11 1 min read Like