利用sort方法与Math.random()方法辅助实现
const arr = [1, 2, 3, 4, 5, 6];
const newArr = arr.sort(() => Math.random() - 0.5);
console.log(newArr);
//[ 2, 3, 5, 1, 6, 4 ]
利用sort方法与Math.random()方法辅助实现
const arr = [1, 2, 3, 4, 5, 6];
const newArr = arr.sort(() => Math.random() - 0.5);
console.log(newArr);
//[ 2, 3, 5, 1, 6, 4 ]