let obj = {name:'name',age:12,c:'c',A:'test'};
console.log(obj)
let tmpObj1= {};
let tmpObj2= {};
let keys1 = Object.keys(obj).sort();//字母升序
let keys2 = Object.keys(obj).sort().reverse();//字母降序
console.log(keys1)
console.log(keys2)
keys1.forEach((item,index)=>{
//console.log(item,index)
tmpObj1[item] = obj[item]
})
keys2.forEach((item,index)=>{
//console.log(item,index)
tmpObj2[item] = obj[item]
})
console.log(tmpObj1);
console.log(tmpObj2);
image.png
网友评论