The sort method

The sort() method is used to sort the element of an array in alphabetical order.

var Fruits = new Array ("pears", "mangoes" , "bananas" , "apples");
Fruits.sort();
document.write(Fruits);

This will output the elements of the array in alphabetical order “apples, bananas, mangoes, pears”.

Leave a Reply