We can sort an array alphabetically using the
This sample script includes an array variable named cars. There are four elements in the array, Volvo, Acura, Honda, and Lexus.
var cars = ["Volvo,", "Acura", "Honda", "Lexus"];
document.getElementById("demo").innerHTML = cars;
Let's go ahead and add the
sort() method into the script to sort the elements alphabetically from A to Z.
Preview the page in your web browser to make sure it worked.
We can also reverse sort the elements in an array using the