当前位置:网站首页>JS -- take a number randomly from the array every call, and it cannot be the same as the last time
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
2022-07-02 11:17:00 【Month better】
const arr = [1, 2, 3, 4, 5];
let ranArr = [];
const randomchoice = function factory(arr) {
let rnd = Math.floor(Math.random() * arr.length);
if (ranArr.includes(rnd)) return factory(arr);
ranArr.push(rnd);
return arr[rnd];
};
console.log(randomchoice(arr));
console.log(randomchoice(arr));
console.log(randomchoice(arr));
console.log(randomchoice(arr));
console.log(randomchoice(arr));
边栏推荐
- The most detailed MySQL installation tutorial
- Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
- STM32 single chip microcomputer programming learning
- TIPC介绍1
- 函数式接口和方法引用
- Iii. Système de démarrage et d'horloge à puce
- Creation and use of unified links in Huawei applinking
- Solve the problem of data blank in the quick sliding page of the uniapp list
- [applinking practical case] share in app pictures through applinking
- 原生方法合并word
猜你喜欢
Flink two Open, implement Batch Lookup join (attached source)
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
Importerror: impossible d'importer le nom « graph» de « graphviz»
Solve the problem of data blank in the quick sliding page of the uniapp list
III Chip startup and clock system
QT学习日记7——QMainWindow
三.芯片啟動和時鐘系統
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
How to implement tabbar title bar with list component
随机推荐
SQLite modify column type
Resources读取2d纹理 转换为png格式
How to implement tabbar title bar with list component
Resources reads 2D texture and converts it to PNG format
QT学习日记7——QMainWindow
Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
Uncover the secrets of Huawei application market application statistics
tqdm的多行显示与单行显示
The first white paper on agile practice in Chinese enterprises was released | complete download is attached
Multi line display and single line display of tqdm
Solve the problem of data blank in the quick sliding page of the uniapp list
PowerBI中导出数据方法汇总
STM32单片机编程学习
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
Pit of the start attribute of enumrate
OpenMLDB Meetup No.4 会议纪要
TIPC messaging3
Functional interfaces and method references
Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
SSRF