function shuffle(arr){ var newArr = []; while (arr.length){ var randomIndex = Math.floor(Math.random() * arr.length); newArr.push(arr.splice(randomIndex,1)[0]); } return newArr; }
参考:https://juejin.im/post/5cef46226fb9a07eaf2b7516