sort() 通常对一维数组进行排序
sortOn() 对关联数组或内部含对象数组排序
reverse() 倒转数组
sort()
简单的排序:基本的排序是按 字母顺序 排序
如:"abcd" 或 1 10 2 3 都是字母顺序的.任何排序操作都会改变数组的索引
1:按数字大小排序
var ary:Array=[1,10,2,5];
ary.sort(Array.NUMBERIC);
//ary=[1,2,5,10]
2: 按降序 排序
ary.sort(Array.DESCENDING);
3:获取排序后的索引 返回一个表似乎排序后的索引数组。不会真的去改变原来的数组
sort(Array.RETURNINDEXEDARRAY):Array
var ary:Array=["a","c","b","d"];
//indexAry 得到是 预排序后的索引 数组。[0,2,1,3]
var indexAry:Array=ary.sort(Array.RETURNiNDEXEDARRAY);
//此时 ary依旧是["a","c","b","d"]
for(var i:int=0;i<indexAry.length;i++)
{
trace(ary[indexAry[i]]);
}
sortOn()
对键排序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
var userList:Array=[{name:"John",age:23},{name:"Linda",age:30},{name:"Kinda",age:18}];
userList.sortOn("age");
for(var i:int=0;i<userList.length;i++){
trace(userList[i].name+" "+userList[i].age);
}
userList.sortOn("age");
for(var i:int=0;i<userList.length;i++){
trace(userList[i].name+" "+userList[i].age);
}