sort用于对象排序

   数组排序 (升序);

    var arr=[1,8,4,12];
    arr.sort(function(a,b){
        return a-b});
  数组排序 (降序);
    var arr=[1,8,4,12];
    arr.sort(function(a,b){
        return b-a});
sort用于对象排序(争对某一字段)

var strJson = [
    {
        "CommentID": 30000000079,
        "CommentText": "111",
        "UserName": "匿名用户",
        "SubmitTime": "2015-02-05 17:40"
    },
    {

        "CommentID": 30000023628,
        "CommentText": "222还能完游戏吗",
        "UserDisplayAddress": "上海闸北",
        "SubmitTime": "2015-06-16 17:00"
    },
    {
        "CommentID": 30000023627,
        "CommentText": "333还没完游戏吗",
        "SubmitTime": "2015-06-16 17:00"
    }];

strJson.sort(function(a,b){
    return new Date(a.SubmitTime)>new Date(b.SubmitTime)
})
日期转换为毫秒

    time ='2015-06-16 17:00';
    time = time.replace(new RegExp("-","gm"),"/");
    var timeHaoMiao = (new Date(time)).getTime(); //得到毫秒数

你可能感兴趣的:(sort用于对象排序)