Javascript: Random element from array

Function to get a random element from a Javascript array.

function rand_elem(items) {
    var item = items[Math.floor(Math.random() * items.length)];

    return item;
}
Leave A Reply
All content licensed under the Creative Commons License