假设有如下数组:

var items = ['1','2','3','4','5','6','7','8','9','10'];

1、从该数组中随机获取一个元素

var rnd = items[Math.floor(Math.random()*items.length)];

2、从该数组中随机获取 n 个元素组成新的数组

function getRandomArrayElements(arr, count) {
    var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
    while (i-- > min) {
        index = Math.floor((i + 1) * Math.random());
        temp = shuffled[index];
        shuffled[index] = shuffled[i];
        shuffled[i] = temp;
    }
    return shuffled.slice(min);
}
var rnd = getRandomArrayElements(items, 5)