Question by
tperry1x · Nov 26, 2015 at 04:15 PM ·
javascriptarrayssortingjavascript-specificreverse
Sort an array in reverse alphabetical order
Hi there. I have an array with 3 items inside. Such as:
var tarray = new Array ();
tarray.length = 2;
I might then end up with the array populated in a random order such as:
tarray [0] = "w_h";
tarray [1] = "w_b";
tarray [2] = "w_g";
How do I get the array to sort reverse alphabetically, so the array would be:
tarray [0] = "w_h";
tarray [1] = "w_g";
tarray [2] = "w_b";
Many thanks.
Comment
Best Answer
Answer by Jessespike · Nov 26, 2015 at 04:48 PM
Reverses the order of the elements in the entire ArrayList.
tarray.Reverse();
Answer by tperry1x · Nov 29, 2015 at 08:01 PM
Many thanks @Jessespike I had to use:
tarray.Sort();
tarray.Reverse();
This achieved what I wanted. The first line makes sure my array items are alphabetical, the next reversed that order as suggested. Many thanks.
Your answer
Follow this Question
Related Questions
InvalidCastException 0 Answers
how to not repeat random array 1 Answer
How to sort List of Lists by a certain Value (C#) 1 Answer
how to not repeat random array 0 Answers