console.log(Math.random().toString(16).substring(2));console.log(Math.random().toString(36).substring(2));上面两行代码toString起到什么作用?方法内的参数是什么意思?为什么最后会生成一个随机字符串?
1 回答
![?](http://img1.sycdn.imooc.com/533e4c5600017c5b02010200-100-100.jpg)
ABOUTYOU
TA贡献1812条经验 获得超5个赞
Math.random()输出0到1(包括0,不包含1)的随机数。
toString(16)将随机数转换为16进制的字符串。
substring(2)截取字符串,因为随机数大于等于0小于1,前两位是“0.”,substring(2)从第三位开始截取到最后。
添加回答
举报
0/150
提交
取消