gpt4 book ai didi

javascript - 从数组中随机选取一个数组元素

转载 作者:行者123 更新时间:2023-11-28 21:11:48 26 4
gpt4 key购买 nike

Possible Duplicate:
How can I return a random value from an array?
Getting random value from an array

如果你有一个数组:

days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

如何从该数组中随机选取一个元素?

最佳答案

var randomDay = days[Math.floor(Math.random()*days.length)]
document.write(randomDay);

关于javascript - 从数组中随机选取一个数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8431075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com