AS3 - Sorting an array of nested arrays

前端 未结 2 583
广开言路
广开言路 2020-12-21 04:14

How would I go about sorting an array of nested arrays, based on the contents of one of the nested arrays elements?

var nestedArray1:Array = new Array(0,0,1)         


        
2条回答
  •  自闭症患者
    2020-12-21 04:40

    Since you can access an array index in the same way as a property (array[2] is the same as array["2"]) you can use sortOn.

    parentArray.sortOn("2", Array.NUMERIC);
    

    You can also use the other indices as second or third sort fields if don't want an unpredictable order for equal entries.

    parentArray.sortOn(["2","1","0"], Array.NUMERIC);
    

提交回复
热议问题