Home > Article > Web Front-end > How to find the minimum value of an array using JavaScript
In JS, you can use the min() method of the Math object and the extension operator "..." to find the minimum value of the array; the min() method can return the minimum value in the specified number list. Numeric, the spread operator can convert an array into a comma-separated sequence of parameters, implementing the syntax "Math.min(...arr)".
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 and the spread operator "..." to find the minimum value of the array.
Implementation code:
var arr=[2,6,1,5,22,3,66,12,9]; var min=Math.min(...arr); console.log("最小值为:"+min);
Output result:
##Description:
min( ) method returns the number with the smallest value in the specified list of numbers. Grammar format:Math.min(n1,n2,n3,...,nX)The spread operator (...) was introduced in es6, which is used to convert an array into a parameter sequence separated by commas. It is commonly used in function calls when the number of parameters is uncertain. Arrays The usage of merge is as follows: 1. Get the maximum value of the array
function getMaxArray(arr){ return Math.max(...arr); }2. Merge the array
var arr=[1,2,3,4]; var arr1=[1,2]; var arr2=[...arr,...arr1]//arr+arr1合并数组[Recommended learning:
javascript advanced tutorial 】
The above is the detailed content of How to find the minimum value of an array using JavaScript. For more information, please follow other related articles on the PHP Chinese website!