处理数组的基本方法
- Math.ceil(); 执行向上舍入,即它总是将数值向上舍入为最接近的整数;
- Math.floor(); 执行向下舍入,即它总是将数值向下舍入为最近接近的整数;
- Math.round(); 执行标准舍入,即它总是将数值四舍五入为最接近的整数;
- Math.abs(); 返回参数的绝对值;
- Math.min() 和 Math.max(); 用于确定一组数值中最小值和最大值;
- Math.pow(num,power); 返回num的power次幂;
- Math.sqrt(); 返回参数的平方根;
- Math.random(); 返回大于等于0小于1的一个随机数;
//0-x之间的随机数:Math.random()*x; console.log(parseInt(Math.random()*10)); //x-y之间的随机数:Math.random()*(y-x)+x; console.log(parseInt(Math.random()*(50-30)+30));