通过数组里的时间重新排序数组
var timeArr = [ {"Date": "2019-07-07 10:00:00",'con':'11'}, {"Date": "2018-07-09 1:00:00",'con':'22'}, {"Date": "2019-07-07 4:00:00",'con':'33'}, {"Date": "2018-07-31 2:00:00",'con':'44'} ]; var newArr = []; for(var i = 0; i < timeArr.length; i++){ newDate = (timeArr[i].Date).replace(new RegExp("-", "gm"), "/"); HaoMiao = (new Date(newDate)).getTime(); //得到毫秒数 newArr.push(timeArr[i]) newArr[i].time = HaoMiao; } var arr = newArr.sort(sortDate); //arr就是最终的排序后的数组 console.log(arr) function sortDate(a,b){ return a.time-b.time }
posted on 2018-09-13 09:36 婆婆买了只kitty 阅读(562) 评论(0) 编辑 收藏 举报