当前位置:网站首页>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));
边栏推荐
- Overview of drug discovery-01 overview of drug discovery
- Lmsoc: a socially sensitive pre training method
- 模块化开发
- 什麼是數字化?什麼是數字化轉型?為什麼企業選擇數字化轉型?
- 1382. 将二叉搜索树变平衡-常规方法
- Evaluation - rank sum ratio comprehensive evaluation
- Adobe Premiere foundation - sound adjustment (volume correction, noise reduction, telephone tone, pitch shifter, parameter equalizer) (XVIII)
- MySQL - function
- 嵌入式必学!硬件资源接口详解——基于ARM AM335X开发板 (下)
- 面试官问:JS的this指向
猜你喜欢

Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known

类的初始化与回调的用法

Hi, you have a code review strategy to check!

面试官问:JS的继承

LMSOC:一种对社会敏感的预训练方法

Numpy----np.reshape()

Web3 技术初体验以及相关学习资料

Evaluation - rank sum ratio comprehensive evaluation

评价——灰色关联分析

Interviewer asked: Inheritance of JS
随机推荐
Coscon'22 lecturer solicitation order
评价——秩和比综合评价
How to optimize the "message" list of IM
【嵌入式基础】串口通信
Prometeus 2.35.0 new features
有监督、无监督与半监督学习
Four classic training modes in comparative learning
General process after reference layer reboot
[Yocto RM] 4 - Source Directory Structure
Numpy----np.reshape()
【ELT.ZIP】OpenHarmony啃论文俱乐部—数据密集型应用内存压缩
How to study efficiently
Capacitor
树莓派实现温控风扇智能降温
面试官问:JS的继承
TIA botu_ Concrete method of making analog input and output Global Library Based on SCL language
frp实现内网穿透
Comprehensive evaluation of free, easy-to-use and powerful open source note taking software
Xctf attack and defense world misc wage earner advanced zone
To understand what is synchronous, asynchronous, serial, parallel, concurrent, process, thread, and coroutine