SOURCE

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--;
}
// function getRandomFromArr(arr, num) {
// 	let len = arr.length;
// 	if (len <= num) {
// 		return arr;
// 	} else {
// 		let result = [];
// 		for (let i = 0; i < num; i++) {
// 			let index = ~~(Math.random() * len) + i;
// 			result[i] = arr[index];
// 			arr[index] = arr[i];
// 			len--;
// 		}
// 		return result;
// 	}
// }
console.log(result);
console 命令行工具 X clear

                    
>
console