const list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
list.sort(() => Math.random() - 0.5)
(9) [2, 6, 8, 1, 7, 5, 9, 3, 4]
list.sort(() => Math.random() - 0.5)
(9) [8, 1, 3, 4, 9, 7, 6, 2, 5]
list.sort(() => Math.random() - 0.5)
(9) [9, 8, 5, 7, 6, 1, 3, 2, 4]
list.sort(() => Math.random() - 0.5)
(9) [1, 5, 7, 8, 6, 9, 2, 4, 3]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。