//原数组 var arr = [0,1,2,3,4,5,6,7,8,9,10,11]; //输出数组 var out = []; //输出个数 var num = 5; while(out.length < num){ var temp = (Math.random()*arr.length) >> 0; out.push(arr.splice(temp,1)); } alert(out);
//原数组 var arr = [0,1,2,3,4,5,6,7,8,9,10,11]; //输出数组 var out = []; //输出个数 var num = 5; while(out.length < num){ var temp = (Math.random()*arr.length) >> 0; out.push(arr.splice(temp,1)); } alert(out);
转载于:https://www.cnblogs.com/chenmiaosong/p/7505130.html