get min or max from variables in array code example
Example 1: find min and max date in array javascript
const dates = [];
dates.push(new Date('2011/06/25'));
dates.push(new Date('2011/06/26'));
dates.push(new Date('2011/06/27'));
dates.push(new Date('2011/06/28'));
const maxDate = new Date(Math.max.apply(null, dates));
const minDate = new Date(Math.min.apply(null, dates));
Example 2: find max and min value in array javascript
var numbers = [1, 2, 3, 4];
Math.max(...numbers) // 4
Math.min(...numbers) // 1