码迷,mamicode.com
首页 > 编程语言 > 详细

6.JavaScript数组乱序排序

时间:2020-04-22 11:38:59      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:char   name   log   src   color   class   onclick   乱序   init   

1.对数组打乱顺序

技术图片技术图片
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
        arr.sort(function (a, b) {
            return Math.random() - 0.5; //使用随机数,大于0.5的往后排,小于0.5的往前排
        })
        console.log(arr);
    </script>
</body>

</html>
index.html

 

6.JavaScript数组乱序排序

标签:char   name   log   src   color   class   onclick   乱序   init   

原文地址:https://www.cnblogs.com/lanshanxiao/p/12750799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!