Home  >  Article  >  Web Front-end  >  How to find the minimum value in javascript

How to find the minimum value in javascript

青灯夜游
青灯夜游Original
2021-06-18 17:04:125041browse

In JavaScript, you can use the min() method of the Math object to find the minimum value. This method can return the minimum value among zero or more values. The syntax format is "Math.min(value 1, value 2, value 3,..., value N) "; if any parameter cannot be converted to a numerical value, "NaN" is returned.

How to find the minimum value in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In javascript, you can use the min() method of the Math object to find the minimum value.

Let’s learn about it through an example:

console.log(Math.min(5,10));
console.log(Math.min(0,150,30,20,38));
console.log(Math.min(-5,10));
console.log(Math.min(-5,-10));
console.log(Math.min(1.5,2.5));

Output:

How to find the minimum value in javascript

Explanation:

Math.min() Returns the minimum of zero or more values.

Syntax

Math.min(n1,n2,n3,...,nX)

Return value:

  • The smallest number among the given values.

Description:

Since min is a static method of Math, it should be used like this: Math.min(), not as a method of the Math instance you created (Math is not a constructor).

If there are no parameters, the result is Infinity.

If any parameter cannot be converted to a numeric value, the result is NaN.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of How to find the minimum value in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn