1,使用Math对象获取最大值的方法max()和获取最小值min()方法。
var max=Math.max(3,5,7,9,6,4,2) // 9
var min=Math.min(3,5,7,9,6,4,2) // 2
使用Math对象获取数组中的最大值和最小值:
会使用到apply()方法,将Math对象作为apply()的第一个参数,从而正确的设置this。然后将数组作为第二个参数。如:
var values=[1,3,5,9,6,4,11,22,5,8,44,56,2,7];
var max=Math.max.apply(Math,values); //56
var min=Math.min.apply(Math,values); //1
2.使用random()方法生成随机数:
公式:值=Math.floor(Math.random()*可能值的总数+第一个可能的值)
如:1到10之间的随机值:可能值:1,2,3,4,5,6,7,8,9,10
var num=Math.floor(Math.random()*10+1);
如:2到10之间的随机值:可能值:2,3,4,5,6,7,8,9,10
var num=Math.floor(Math.random()*9+2);
-------------------------------------------------------------------------------------------------------------------------------------------------------------------如遇到问题:+WX:WAZJ-0508,及时联系---------------------------------------------------------------------------------------------------------------------------------------------------