方法一:
function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1) + min) } function shuffle(arr) { let _arr = arr.slice() for (let i = 0; i < _arr.length; i++) { let j = getRandomInt(0, i) let t = _arr[i] _arr[i] = _arr[j] _arr[j] = t } return _arr } console.log(shuffle([11,22,33,4,5,6]))
方法二:
arr.sort(function(){ Math.random()>0.5?1:-1 })