一、
Math.round(num) 四舍五入
Math.random() 随机小数
Math.pow(x, y) 返回 x 的 y 次幂的值
Math.round(Math.random()*Math.pow(10, 10))
二、
new Array(10) new 一个长度为10的数组对象
array.fill() 使用固定的值填充数组
Math.floor() 向下取整
array.join(‘分隔符’) 将数组单元中存储的数据,拼接为一个字符串
new Array(10).fill(1).map(num => Math.floor(num * Math.random() * 10)).join('');
这篇博客介绍了JavaScript中的一些数学操作函数,如Math.round用于四舍五入,Math.random生成随机小数,以及Math.pow计算指定数的幂。同时,讲解了如何使用数组方法newArray和fill创建并填充数组,以及Math.floor进行向下取整。通过实例展示了如何结合这些方法生成一个包含随机整数的字符串数组,并使用join方法将其转换为字符串。
5948

被折叠的 条评论
为什么被折叠?



