JS数组中随机选出一项

JS数组

js数组我们经常在开发中使用,那么,我们如何快速的随机选择其中一项呢

代码:

var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119];

var randomItem = items[Math.floor(Math.random() * items.length)];
console.log(randomItem);

原文地址:https://www.cnblogs.com/agen-su/p/11635579.html