js随机取数组里的一个元素

JavaScript - 随机获取数组元素

var myArray = ['one', 'two', 'three', 'four', 'five'];
var rand = Math.floor(Math.random() * myArray.length);
var rValue = myArray[rand];
console.log(rValue)
此条目发表在js分类目录。将固定链接加入收藏夹。

发表回复