前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >js & array & shuffle

js & array & shuffle

原创
作者头像
用户7436765
修改2020-06-08 14:34:55
2.5K0
修改2020-06-08 14:34:55
举报
文章被收录于专栏:121js121js

js & array & shuffle

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]

Array.sort()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

refs

https://flaviocopes.com/how-to-shuffle-array-javascript/

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • js & array & shuffle
    • Array.sort()
      • refs
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档