Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multidimensional array sort in AS3

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
like image 777
pioSko Avatar asked Dec 07 '11 16:12

pioSko


1 Answers

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.

like image 140
kapex Avatar answered Nov 10 '22 20:11

kapex