What would be the easiest way to do a multi sort in AS3. Something similar to array_multisort() in PHP... like this: sort a multidimentional array using array_multisort
What I have
var COUNTRIES:Array = [["AD","Andorra"],["AE","United Arab Emirates"],["AF","Afghanistan"],["AG","Antigua & Barbuda"],["AI","Anguilla"]];
.. which looped outputs
Andorra
United Arab Emirates
Afghanistan
Antigua & Barbuda
Anguilla
... what I need is to sort it against the second index of each, so I get
Afghanistan
Andorra
Anguilla
Antigua & Barbuda
United Arab Emirates
It's simple:
COUNTRIES.sortOn("1");
It works because you can access an array index by using a string, just like a property: array["0"]
. So sortOn
uses the "1"
'property' of each inner array for sorting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With