您的位置:首页 > Web前端 > JavaScript

JSON转数组排序

BradyCC 2019-04-18 17:25 56 查看 https://blog.csdn.net/bradycc/
//JSON转数组排序

var log = {
'2019-01-19': {createdate: '2019-01-19', gifnum: '1.5'},
'2019-01-17': {createdate: '2019-01-17', gifnum: '2.5'},
'2019-01-18': {createdate: '2019-01-18', gifnum: '3.5'},
'2019-01-20': {createdate: '2019-01-20', gifnum: '4.5'},
'2019-01-15': {createdate: '2019-01-15', gifnum: '5.5'},
'2019-01-13': {createdate: '2019-01-13', gifnum: '6.5'}
}, arr = [];

for(let i in log) {
arr = [...arr, log[i]].sort((a,b) => {
return new Date(b.createdate) - new Date(a.createdate);
});
}

console.log(arr);
标签: