JavaScript Sorting Arrays
The sort() method sorts an array alphabetically: Example var fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; fruits.sort(); // Sorts the elements of fruits Try it Yourself » Reversing an Array The reverse() method reverses the elements in an array. You can use it to sort an array in descending order: Example var fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; fruits.sort(); // First sort the elements of fruits fruits.reverse(); // Then reverse the […]
