javascript如何在一个数组里随机选出不重复的10项?
var result = []; var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]; var count = arr.length; for (var i = 0; i < 10; i++) { var index = ~~(Math.random() * count) + i; result[i] = arr[index]; arr[index] = arr[i]; count--; } console.log(result);