How about augmenting the built-in Array object to use Math.max/Math.min instead:

Array.prototype.max = function() {
  return Math.max.apply(null, this);
};

Array.prototype.min = function() {
  return Math.min.apply(null, this);
};

let p = [35,2,65,7,8,9,12,121,33,99];

console.log(`Max value is: ${p.max()}` +
  `\nMin value is: ${p.min()}`);

Here is a JSFiddle.

Augmenting the built-ins can cause collisions with other libraries (some see), so you may be more comfortable with just apply'ing Math.xxx() to your array directly:

var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);

Alternately, assuming your browser supports ECMAScript 6, you can use spread syntax which functions similarly to the apply method:

var min = Math.min( ...arr ),
    max = Math.max( ...arr );
Answer from Roatin Marth on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
console.log(Math.min(2, 3, 1)); // Expected output: 1 console.log(Math.min(-2, -3, -1)); // Expected output: -3 const array = [2, 3, 1]; console.log(Math.min(...array)); // Expected output: 1 · js · Math.min() Math.min(value1) Math.min(value1, value2) Math.min(value1, value2, /* …, */ valueN) value1, …, valueN ·
🌐
Programiz
programiz.com › java-programming › library › math › min
Java Math min()
min = Math.min(min, arr[i]); } System.out.println("Minimum Value: " + min); } } In the above example, we have created an array named arr.
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › max-and-min-examples.html
Math.max and Math.min Examples — Introduction to Professional Web Development in JavaScript documentation
Math.min(x, y, z, ...) This method finds and returns the smallest value from a set of numbers (x, y, z,...). To find the minimum value in an array, see below. Example · console.log(Math.min(2, 3, 100.01, 0, -5.2, 100)); Console Output · -5.2 · Unfortunately, the max and min methods will ...
🌐
W3Schools
w3schools.com › jsref › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
🌐
Medium
medium.com › @vladbezden › how-to-get-min-or-max-of-an-array-in-javascript-1c264ec6e1aa
How to get min or max of an array in JavaScript | by Vlad Bezden | Medium
September 2, 2016 - The Math.min() function returns the smallest of zero or more numbers. ... But what if we have array of number and we would like to find min and max value in it.
🌐
Programiz
programiz.com › javascript › library › math › min
JavaScript Math min()
Here, ... is the spread operator that destructures the array and passes the array values as arguments to min(). The method then finds the smallest number. // min() with string argument let numbers1 = Math.min("Dwayne", 2, 5, 79); console.log(numbers1);
🌐
Math.js
mathjs.org › docs › reference › functions › min.html
math.js
math.min(2, 1, 4, 3) // returns 1 math.min([2, 1, 4, 3]) // returns 1 // minimum over a specified dimension (zero-based) math.min([[2, 5], [4, 3], [1, 7]], 0) // returns [1, 3] math.min([[2, 5], [4, 3], [1, 7]], 1) // returns [2, 3, 1] math.max(2.7, 7.1, -4.5, 2.0, 4.1) // returns 7.1 math.min(2.7, 7.1, -4.5, 2.0, 4.1) // returns -4.5
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-min-element-in-an-array
JavaScript – Min Element in an Array - GeeksforGeeks
July 23, 2025 - Note: You must add a conditional ... them. This method uses the Math.min() function to find the smallest value in the array by spreading the elements as individual arguments....
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › min
JavaScript Math min() - Find Minimum Value | Vultr Docs
November 27, 2024 - The variables a, b, and c are evaluated by Math.min(), which returns the smallest value, -1. Expand array elements as individual arguments using the spread syntax.
🌐
CoreUI
coreui.io › answers › how-to-find-the-minimum-value-in-an-array-in-javascript
How to find the minimum value in an array in JavaScript · CoreUI
September 21, 2025 - Use Math.min with spread operator to efficiently find the smallest number in a JavaScript array with modern syntax.
Top answer
1 of 4
39

I realized the answer as I was posting my own question: This is the most succinct way of taking the min of an array x in JavaScript. The first argument is totally arbitrary; I find the 0 confusing because the code intuitively means "Take the min of 0 and x," which is absolutely not the case. Using the Math object makes more sense for human-readability, but the Raphael.js authors are obsessed with minification and 0 is three bytes shorter.

See http://ejohn.org/blog/fast-javascript-maxmin/

For readability's sake, I'd strongly urge people to stop doing this and instead define a function along the lines of

function arrayMin(arr) { return Math.min.apply(Math, arr); };
2 of 4
14

The reason is this:

  • Your input x is an array

  • The signature of Math.min() doesn't take arrays, only comma separated arguments

  • If you were using Function.prototype.call() it would have almost the same signature, except the first argument is the this context, i.e. who's "calling"

    • Example: Math.min.call(context, num1, num2, num3)
  • The context only matters when you refer to this inside the function, e.g. most methods you can call on an array: Array.prototype.<method> would refer to this (the array to the left of the 'dot') inside the method.

  • Function.prototype.apply() is very similar to .call(), only that instead of taking comma-separated arguments, it now takes an array after the context.

    • Function.prototype.call(context, arg1, arg2, arg3)
    • Function.prototype.apply(context, [arg1, arg2, arg3])
  • The 0 or null that you put in as the first argument is just a place shifter.

🌐
PHP
php.net › manual › en › function.min.php
PHP: min - Manual
Math Functions · (PHP 4, PHP 5, ... arguments): min(array $value_array): mixed · If the first and only parameter is an array, min() returns the lowest value in that array....
🌐
GeeksforGeeks
geeksforgeeks.org › find-the-min-max-element-of-an-array-using-javascript
Find the min/max element of an Array using JavaScript | GeeksforGeeks
To find the minimum or maximum element in a JavaScript array, use Math.min or Math.max with the spread operator.
Published   January 7, 2025
🌐
Stack Abuse
stackabuse.com › javascript-get-min-and-max-element-of-array
JavaScript: Get Min and Max Element of Array
April 6, 2023 - In this guide, learn how to get the largest and smallest (min and max) elements of an array in JavaScript, using `Math.min()` and `Math.max()` methods, the spread operator, the `reduce()` method, the `apply()` method and a `for` loop.
🌐
Reddit
reddit.com › r/javascript › why don't math.max and math.min accept arrays? why are they n-arity functions?
r/javascript on Reddit: Why don't Math.max and Math.min accept arrays? Why are they n-arity functions?
February 13, 2017 -

Edit: I am not asking for a way to use these methods with arrays. What I am asking is why in the first place do they not accept arrays.

However, I will list the solutions mentioned:

  1. Math.max.apply(null, arr)

  2. Math.max(...arr)

  3. arr.reduce((max, current) => (current > max ? current : max), -Infinity);

🌐
W3docs
w3docs.com › javascript
How to Find the Min/Max Elements in an Array in JavaScript
How to Find the Min/Max Elements in an Array in JavaScript · There are multiple methods to find the smallest and largest numbers in a JavaScript array, and the performance of these methods varies based on the number of elements in the array. Let’s discuss each of them separately and give the testing results in the end. For regular arrays you can use the Math.max with three dots: let max = Math.max(...arrayOfNumbers); Javascript Math.max find max in array ·