Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 414 Bytes

File metadata and controls

18 lines (13 loc) · 414 Bytes

How to Sort Arrays in JavaScript

The sort() method sorts an array alphabetically:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();

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

You can use it to sort an array in descending order:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();        // First sort the elements of fruits
fruits.reverse();