js 随机获取数组几个元素
`function randomArray(arr, count) {
let shuffled = arr.slice(0); let i = arr.length; let min = i - count; let temp; let index;
while (i-- > min) { index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
//console.log(shuffled);
}
return shuffled.slice(min);
}
var arry= ['101', '202', '103', '45', '65', '76', '77', '58', '59', '510'];
console.log( randomArray(items, 4) );`