当前位置:网站首页>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));

边栏推荐
猜你喜欢

Creation and use of unified links in Huawei applinking

Thanos Receiver

Implement custom drawer component in quick application

Solve the problem of data blank in the quick sliding page of the uniapp list
![[play with FPGA learning 4 in simple terms ----- talk about state machine design]](/img/e0/95f8b8c5116c57455e54ad12372f12.png)
[play with FPGA learning 4 in simple terms ----- talk about state machine design]

Multi line display and single line display of tqdm

From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang

MTK full dump grab

MTK full dump抓取

TIPC Cluster5
随机推荐
III Chip startup and clock system
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
Jinshanyun - 2023 Summer Internship
Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
PKG package manager usage instance in FreeBSD
Is the account above changtou school safe?
Jenkins installation
Is bond fund safe? Does the bond buying foundation lose principal?
mysql 基本语句
在网上开股票账户安全吗?我是新手,还请指导
The first white paper on agile practice in Chinese enterprises was released | complete download is attached
js中给数组添加元素的方法有哪些
TIPC Cluster5
JVM garbage collector
Summary of cases of players' disconnection and reconnection in Huawei online battle service
Primary key policy problem
二.Stm32f407芯片GPIO编程,寄存器操作,库函数操作和位段操作
Jenkins安装
ros缺少catkin_pkg
原生方法合并word