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)
function getMaxArray(arr){ return Math.max(...arr); }
var arr=[1,2,3,4]; var arr1=[1,2]; var arr2=[...arr,...arr1]//arr+arr1合并数组
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!