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 Web Docs
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 - var nums = [1, 2, 3] Math.min.apply(Math, nums) // 1 Math.max.apply(Math, nums) // 3 Math.min.apply(null, nums) // 1 Math.max.apply(null, nums) // 3 · With ES6/ES2016 destructuring assignment it becomes easier · The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.
🌐
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
Function min
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.
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....
🌐
MathWorks
mathworks.com › matlab › data import and analysis › descriptive statistics
min - Minimum elements of array - MATLAB
If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A. If A is a multidimensional array, then min(A) operates along the first dimension of A whose size does not equal 1, treating the elements as vectors. The size of M in this dimension becomes 1, while ...
🌐
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 ·
🌐
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.
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › min and max value of an array
Min and max value of a JavaScript array - 30 seconds of code
December 30, 2023 - fn : val => val[fn])); const maxBy = (arr, fn) => Math.max(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], x => x.n); // 2 minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2 maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], x => x.n); // 8 maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 ... An article collection of math helpers and algorithms implemented in JavaScript. ... JavaScript arrays have a very robust API offering some amazing tools.
🌐
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