The most viewed posts

Registry Reviver

Web Development Services

Contact Me

How to clean up Windows Computer

About Desktop Icons in Windows Computer

Driver Booster

CCleaner

How to make a computer secure and run faster

Myanmar font and keyboard for Windows

Advanced System Care

The most viewed items

Dell Inspiron 5559

Desktop Hard Disk

Laptop RAM

SONY Playstation Portable

HP ProBook 430

External Hard Disk

Laptop

Please login to start chat

ZilaStar ICT Apr 04 2022, 21:01:00
Category : JavaScript Tutorials

Sort() and reverse() alphabetically (JS Array Sort)

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "jsSort()">Sort</button>&nbsp;&nbsp;
<button type = "button" onclick = "jsReverse()">Reverse</button>
<script>
var cities = ["Yangon", "Mandalay", "Naypyidaw", "Meikhtila", "Bagan"];
document.getElementById("demo").innerHTML = cities.join(" * ");

function jsSort(){
var sort = cities.sort().join(" * ");
document.getElementById("demo").innerHTML = sort;
}

function jsReverse(){
var reverse = cities.reverse().join(" * ");
document.getElementById("demo").innerHTML = reverse;
}
</script>
</body>
</html>

  • Comments:

    No comment to show.

    To Contact
    Available Services
    Terms and Conditions