当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JavaScript数组乱序排序

JavaScript数组乱序排序

2020年04月22日  | 移动技术网IT编程  | 我要评论

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>

 转自:https://www.cnblogs.com/lanshanxiao/p/12750799.html

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网