将数组中0-9随机打乱
function a(){ var l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var k = []; var lenl = 10; for(var i=0; i<10; i++){ var index = Math.floor(Math.random() * lenl); k[i] = l[index]; l[index] = l[lenl - 1]; lenl -= 1; } console.log("k",k) } 输出结果 Array(10) 0: 7 1: 6 2: 3 3: 9 4: 1 5: 5 6: 0 7: 4 8: 2 9: 8