JavaScript sort() Function Example (Descending Order)

JavaScript sort() Function sorts the item alphabetically or numeric order.

Example

<html>
<head>
    <title>JavaScript Array sort() function</title>
</head>
<body>
    <script type="text/javascript">
        function Sort_Number(x, y) {
            return y - x;
        }

        var num = ["12", "20", "58", "8", "45", "90"];
        document.write("Sorting Numbers: " + num.sort(Sort_Number));
    </script>
</body>
</html>

Run it...   »

Example Result