Mega Code Archive

 
Categories / Flash ActionScript / Array
 

Get the sorted order of an arrays elements without changing the original array

package{   import flash.display.Sprite;      public class Main extends Sprite{     public function Main(){         var words:Array = ["t", "r", "a", "j"];         var indices:Array = words.sort(Array.RETURNINDEXEDARRAY);         trace(words);            trace(indices);          for(var i:int = 0; i < words.length; i++) {           trace(words[indices[i]]);         }     }   } } t,r,a,j 2,3,1,0 a j r t