把数组中的数字从大到小排序,不包括非数

来源:互联网 发布:卡密社区源码 编辑:程序博客网 时间:2024/06/04 08:05
<!doctype html><html lang="zh-cn"><head>    <meta charset="UTF-8">    <title>把数组中的数字从大到小排序,不包括非数</title></head><body>    <script>        var arr=[1,2,3,4,5,'d','ee',66,10,7,888,'a','b','cc'];        var arr2=[];        for(var i=0; i<arr.length; i++){            if(typeof arr[i] === 'number' && !isNaN(arr[i])){                arr2.push(arr[i]);            }        }            arr2.sort( function order(a,b){              return b-a;            });           document.write(arr2);        </script></body></html>

0 0
原创粉丝点击