📌  相关文章
📜  如何从数组中获取随机项 - Javascript 代码示例

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

代码示例4
//Function to make it easier
Array.prototype.random = function() {
    return this[Math.floor((Math.random() * this.length))];
};

var colors = ["red","blue","green","yellow"];
var randomColor = colors.random();