javascript函数2——排序

<!DOCTYPE html>
<html>
<head>
    <title>javascript排序</title>
    <meta charset="UTF-8">
    <script type="text/javascript">
        //根据数字进行函数的排序
        function sortByNum(a,b){
            return a-b;
        }
        var as = [1,2,"11","33","12",190];
        //对于js而言,默认是按照字符串来实现排序的
        as.sort(sortByNum);
        alert(as);


    </script>
</head>
<body>

</body>
</html>

  

posted on 2015-02-07 13:35  aicpcode  阅读(122)  评论(0编辑  收藏  举报

导航