简单写写,思路还是比较简单
<script>
let [oldArray, newArray] = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []];
let len = oldArray.length;
for (let i = 0; i < len; i++) {
let index = Math.floor(Math.random() * oldArray.length);
newArray.push(oldArray[index]);
oldArray.splice(index, 1);
}
console.log(newArray);
</script>