The reverse()
method reverses the elements in an array.
You can use it to sort an array in descending order:
Example
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); // First sort the elements of fruits
fruits.reverse(); // Then reverse the order of the elements
fruits.sort(); // First sort the elements of fruits
fruits.reverse(); // Then reverse the order of the elements
Practice Excercise Practice now