The sortOn( ) can sort on more than one field : sortOn « Array « Flash / Flex / ActionScript






The sortOn( ) can sort on more than one field

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var cars:Array = new Array(  );
        cars.push({make: "H",    year: 1997, color: "maroon"});
        cars.push({make: "Chrysler", year: 2000, color: "beige"});
        cars.push({make: "Mercedes", year: 1985, color: "blue"});
        cars.push({make: "Fiat",     year: 1983, color: "gray"});
             
        cars.sortOn(["year", "make"]);
             
        for (var i:int = 0; i < cars.length; i++) {
          trace(cars[i].color + "\t" + 
                cars[i].year + "\t" + 
                cars[i].make);
        }
        cars.sortOn(["make", "year"]);
             
        for (var i:int = 0; i < cars.length; i++) {
          trace(cars[i].color + "\t" + 
                cars[i].year + "\t" + 
                cars[i].make);
        }
    }
  }
}

        








Related examples in the same category

1.There are five such optional flags that you can pass to either sort() or sortOn():
2.sortOn( ) supports sort modifiers