freeCodeCamp
forum.freecodecamp.org › javascript
Math.min and Math.max methods with JS - JavaScript
May 23, 2019 - I first wrote this code: let numbers = (10, 15, 59, 20); let a = Math.max(numbers); console.log(a); …which display 20 in the console. I’ve noticed that it always returns the last number of the numbers variable. Then, i wrote this (I’ve found it on W3S and modify it a bit): function myFunction() { var a = Math.min(5, 10); var b = Math.min(0, 150, 30, 20, 38); var c = Math.min(-5, 10); var d = Math.min(-5, -10); var e = Math.min(1.5, 2.5); console.log(a + " " + b + " " + ...
Videos
00:56
JavaScript Math min() method - JavaScript Tutorial for Beginners ...
05:23
How to Find Maximum and Minimum in an Array in JavaScript ...
01:00
JavaScript Methods | Math.min() and Math.max() - YouTube
max and min methods in Math object in JavaScript #coding ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
July 20, 2025 - The Math.min() static method returns the smallest of the numbers given as input parameters, or Infinity if there are no parameters.
W3Schools
w3schools.com › jsreF › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
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 ...
Math.js
mathjs.org › docs › reference › functions › min.html
math.js | an extensive math library for JavaScript and Node.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 ·
Educative
educative.io › answers › what-are-mathmin-and-mathmax-in-javascript
What are Math.min() and Math.max() in JavaScript?
In JavaScript, we can use: Math.min() to find the minimum of n elements. Math.max() to find the maximum of n elements.
Reddit
reddit.com › r/learnprogramming › javascript math.min/max function explanation
r/learnprogramming on Reddit: Javascript Math.min/max function explanation
February 10, 2020 -
When using Math.Min or Math.Max methods on arrays why I need to use three dots before the name of the array. Example: Math.max(...arr); .Thanks!
Scaler
scaler.com › home › topics › math min() javascript function
Math min() JavaScript Function - Scaler Topics
May 4, 2023 - There will be multiple instances when we have to find out the minimum of two or more numbers (any type). In Javascript programming, we can use the inbuilt Math.min() function to return the smallest number in a set of numbers (there can be
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math
Math - JavaScript | MDN
This can be achieved with a combination of Math.random() and Math.floor(): ... function random(min, max) { const num = Math.floor(Math.random() * (max - min + 1)) + min; return num; } random(1, 10);
W3Schools
w3schools.com › js › js_math.asp
JavaScript Math Object
Math.min(0, 150, 30, 20, -8, -200); Try it Yourself »
Programiz
programiz.com › javascript › library › math › min
JavaScript Math min()
Become a certified JavaScript programmer. Try Programiz PRO! ... The min() method finds the minimum value among the specified values and returns it. let numbers = Math.min(12, 4, 5, 9, 0, -3); console.log(numbers); // Output: -3
Top answer 1 of 16
1113
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 );
2 of 16
463
var max_of_array = Math.max.apply(Math, array);
For a full discussion see: http://aaroncrane.co.uk/2008/11/javascript_max_api/
TutorialsPoint
tutorialspoint.com › javascript › math_min.htm
JavaScript Math.min() Method
In JavaScript, the Math.min() method accepts any number of arguments, and it returns the minimum value among those arguments.If any of the arguments is not a number, "NaN" (Not-a-Number) is returned.