JavaScript sort() Function Example

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">
        var city = ["Tokyo", "Toronto", "Mumbai", "London"];
        document.write("Amazing Cities: " + city.join(", ") + "<br />");
        document.write(city.sort() + "<br />");
    </script>
</body>
</html>

Run it...   »

Example Result