📜  随机索引 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:19.798000             🧑  作者: Mango

代码示例3
let myList = ["apples", "lemons", "oranges"];
let randomIdx = Math.floor(Math.random() * myList.length);
let randomItem = myList[randomIdx]
console.log(randomItem) // Ex: "lemons"