实现将数组打乱
<script>
/*将数组打乱*/
function randomArr(arr){
var len = arr.length;
for(var i = 0;i<len;i++){
var randomIndex = Math.floor(Math.random()*(len - i));
var item = arr[randomIndex];
arr[randomIndex] = arr[i];
arr[i] = item;
}
return arr;
}
var arr = [1,2,3,4,5,6];
console.log(randomArr(arr));
</script>