js随机数组,随机显示3个不重复数字案例:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script> //原数组 var arr = [0,1,2,3,4,5,6,7,8,9,10,11]; //输出数组 var out = []; //输出个数 var num = 3; while(out.length < num){ var temp = (Math.random()*arr.length) >> 0; out.push(arr.splice(temp,1)); } alert(out); </script> </body> </html>