当前位置:Gxlcms > 前端框架 > js如何对乱序数组进行排序

js如何对乱序数组进行排序

时间:2021-07-01 10:21:17 帮助过:100人阅读

具体代码为:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  11. arr.sort(function (a, b) {
  12. return Math.random() - 0.5; //使用随机数,大于0.5的往后排,小于0.5的往前排
  13. })
  14. console.log(arr);
  15. </script>
  16. </body>
  17. </html>
  18. index.html

推荐教程:js入门教程

以上就是js如何对乱序数组进行排序的详细内容,更多请关注Gxlcms其它相关文章!

人气教程排行