let obj= {
'b': 'foo',
'c': 'bar',
'a': 'baz',
1:'123',
56: '121',
2: '123'
};
function objSort(obj) {
let temp = {};
Object.keys(obj).reverse().forEach(item => {
temp[item] = obj[item]
})
obj = temp;
temp = null;
return obj
}
console.log(objSort(obj)) //{1: "123", 2: "123", 56: "121", a: "baz", c: "bar", b: "foo"}
对象根据key排序
最新推荐文章于 2023-07-12 17:38:52 发布