- 需求,倒序打印出curList的keys,希望结果为 32,26,17,7
var curList = {
'7':'7 7 7 7',
'17':'this is 17',
'32':'32',
'26':'26'
};
let newKeys = Object.keys(curList).sort((a,b) => {
return parseInt(curList[a].num)-parseInt(curList[b].num)
}); //.reverse()
console.log('排序后的keys ',newKeys.join(',')) // 7,17,26,32
newKeys.reverse();
console.log('reverse后的keys ',newKeys.join(',')) //32,26,17,7
//注意下面这种简单sort排序,因为 '7'>'3',所以7排在了最前面,不是我希望的排序方法
let newKeys2 = Object.keys(curList).sort().reverse()
console.log('简单sort倒序后 ',newKeys2.join(',')) //7,32,26,17