We can sort an array alphabetically using this sort method.
This sample script includes an array variable named cars.
There are four elements in the array.
Volvo Acura Honda and Lexus.
Let's go ahead and add the sort method into the script to sort the elements alphabetically from A to
Z.
We start with the variable name cars and then enter the sort method
we'll save our file and preview it in our web browser to make sure it worked.
We can see here that each array element is now sorted in alphabetical order
we can also reverse sought the elements in an array using the reverse method to do so simply type the
following line of code into your script.
Now when we refresh the page you'll notice that each element item is in reverse order.