当前位置:网站首页>JS 数组随机取值(随机数组取值)
JS 数组随机取值(随机数组取值)
2022-06-28 00:05:00 【最凶残的小海豹】
原理:通过随机数取得 [0, 数组长度] 的键值,然后直接获取该键对应的数组值就可以了。
注意:下列代码适用于一维数组,多维数组就自行延伸啦!
function randomArr(arr){
return arr[parseInt(Math.random() * arr.length, 10)]
}
var color_arr = ['#00ff089e', '#0043ff9e', '#fff7009e', '#ff00009e'];
console.log('随机的颜色色值:', randomArr(color_arr));
边栏推荐
- Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
- pytorch_ lightning. utilities. exceptions. MisconfigurationException: You requested GPUs: [1] But...
- Numpy----np.meshgrid()
- Réseau neuronal pour la solution détaillée Multi - diagrammes de fondation zéro
- 766. toplitz matrix
- 药物发现综述-01-药物发现概述
- 【牛客讨论区】第四章:Redis
- Drug interaction prediction based on learning size adaptive molecular substructure
- Is it safe to open an online futures account?
- 深入解析kubernetes controller-runtime
猜你喜欢

9. Openfeign service interface call

向excel中导入mysql中的数据表

要搞清楚什么是同步,异步,串行,并行,并发,进程,线程,协程
![[embedded foundation] serial port communication](/img/b7/18fec20e2d5fa5f226c6f8bb1e93d2.png)
[embedded foundation] serial port communication

Numpy----np.meshgrid()

Original | 2025 to achieve the "five ones" goal! The four products of Jiefang power are officially released

Solve storage problems? WMS warehouse management system solution

数据库的新选择 Amazon Aurora

766. 托普利茨矩阵
![The number of nodes of a complete binary tree [non-O (n) solution > Abstract dichotomy]](/img/56/768f8be9f70bf751f176e40cbb1df2.png)
The number of nodes of a complete binary tree [non-O (n) solution > Abstract dichotomy]
随机推荐
Can you open an account for stock trading in flush? Is it safe?
面试官问:能否模拟实现JS的new操作符
Four classic training modes in comparative learning
Solon 1.8.3 release, cloud native microservice development framework
frp实现内网穿透
Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)
205. 同构字符串
如何阅读一篇论文
[Yocto RM] 4 - Source Directory Structure
What problems should be evaluated before implementing MES management system
Li Kou today's question -522 Longest special sequence
类的初始化与回调的用法
Take n multiple table names of a database as the values of a column in another table (the range can be a table in another database)
【牛客討論區】第四章:Redis
Import the data table in MySQL into Excel
Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
Set collection usage
Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
How to read a paper
Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)