This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.

Smartphone icons created by Freepik - Flaticon

JavaScript Arrays

Sort in Reverse

The reverse() method reverses the elements in an array.

By combining sort() and reverse() you can sort an array in descending order:

// Create and display an array:
const fruits = [" Banana", " Orange", " Apple", " Mango"];
document.getElementById("demo1").innerHTML = fruits;

// First sort the array
fruits.sort();

// Then reverse it:
fruits.reverse();

document.getElementById("demo2").innerHTML = fruits;