当前位置:网站首页>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));
边栏推荐
- 1382. 将二叉搜索树变平衡-常规方法
- 类的初始化与回调的用法
- 766. toplitz matrix
- 什麼是數字化?什麼是數字化轉型?為什麼企業選擇數字化轉型?
- PostgreSQL setting auto increment field
- What is digitalization? What is digital transformation? Why do enterprises choose digital transformation?
- Prometeus 2.35.0 new features
- 将某数据库N多表名作为另外一张表中某一列得值(范围可以是别的数据库中得某张表)
- Interface component telerik UI for WPF Getting Started Guide - how to switch custom styles using themes
- Maimai hot post: Why are big factories keen on making wheels?
猜你喜欢

【牛客讨论区】第四章:Redis

Self supervised learning and drug discovery

Adobe Premiere基础-常用的视频特效(边角定位,马赛克,模糊,锐化,手写工具,效果控件层级顺序)(十六)

Data analysts too hot? Monthly income 3W? Tell you the true situation of this industry with data

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

什麼是數字化?什麼是數字化轉型?為什麼企業選擇數字化轉型?

Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)

数据库查询优化:主从读写分离及常见问题

Import the data table in MySQL into Excel

【嵌入式基础】内存(Cache,RAM,ROM,Flash)
随机推荐
[Yocto RM] 2 - Yocto Project Terms
[Yocto RM] 2 - Yocto Project Terms
声网 VQA:将实时互动中未知的视频画质用户主观体验变可知
ShardingSphere-proxy-5.0.0建立mysql读写分离的连接(六)
如何阅读一篇论文
一张图弄懂 MIT,BSD,Apache几种开源协议之间的区别
Interface component telerik UI for WPF Getting Started Guide - how to switch custom styles using themes
Import the data table in MySQL into Excel
[DNS resolution] set the name DNSPod resolution for domain name access of COM
Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)
学习 pickle
frp实现内网穿透
将某数据库N多表名作为另外一张表中某一列得值(范围可以是别的数据库中得某张表)
数据库的新选择 Amazon Aurora
Xctf attack and defense world misc wage earner advanced zone
766. toplitz matrix
[Yocto RM]1 - System Requirements
机器学习笔记 - 时间序列作为特征
205. isomorphic string
解决ionic4 使用hammerjs手势 press 事件,页面无法滚动问题