从数组中获取随机元素

JavaScript

const sample = arr => arr[Math.floor(Math.random() * arr.length)]

Examples

sample([3, 7, 9, 11]) // 9

posted on 2022-09-07 11:02  小馬過河﹎  阅读(15)  评论(0)    收藏  举报

导航