JavaScript Array数组shuffle与随机获取


11个月前 405次点击 来自 其他

标签: JavaScript

随机数组顺序

let list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
list = list.sort(() => Math.random() - 0.5)

随机获取数组中的任意一个

let list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
var item = items[Math.floor(Math.random()*list.length)];

Made with in Shangrao,China By Devler.

Copyright © Devler 2012 - 2022

赣ICP备19009883号-1