//push添加 //math.floor向下取整 //math.random随机数*10 1-10 //+1
sort() 方法对数组的项目进行排序
/ JavaScript 一个随机数 按顺序插入到数组中
let ar = [2,4,5]
ar.push(Math.floor(Math.random()*10+1))
ar.sort((it,i)=>it-i)
console.log(ar);
本文介绍如何使用JavaScript通过Math.random生成1-10的随机数,将其向下取整后插入到数组ar中,并使用sort()方法对数组进行升序排序。示例代码展示了整个过程。
//push添加 //math.floor向下取整 //math.random随机数*10 1-10 //+1
sort() 方法对数组的项目进行排序
/ JavaScript 一个随机数 按顺序插入到数组中
let ar = [2,4,5]
ar.push(Math.floor(Math.random()*10+1))
ar.sort((it,i)=>it-i)
console.log(ar);

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