js数组的排序

默认排序与按指定的字段自定义的规则排序

//this is a object array 
var listCreate = GetMyCreateGroupsCache();
listCreate.sort();
是针对某个属性的默认排序,即按字符排序
//console.log(listCreate);
listCreate.sort(compareTime);
//console.log(listCreate);
排序后的结果为按SendTime的排序

//比较数组对象的SendTime字段比较时间大小
var compareTime = function (obj1, obj2) {
var val1 = obj1.SendTime;
var val2 = obj2.SendTime;
if (val2 < val1) {
return -1;
} else if (val2 > val1) {
return 1;
} else {
return 0;
}
}