gpt4 book ai didi

javascript - 当某些键是数字时,按对象键对数据排序不起作用

转载 作者:行者123 更新时间:2023-11-30 08:19:13 26 4
gpt4 key购买 nike

<分区>

我的对象包含这样的数据

const testData = {
"11": {
"data": {
"firstName": "firstName",
"lastName": "lastName"
}
},
"12": {
"data": {
"firstName": "firstName",
"lastName": "lastName"
}
},
"00": {
"data": {
"firstName": "firstName",
"lastName": "lastName"
}
},
"01": {
"data": {
"firstName": "firstName",
"lastName": "lastName"
}
},
"final": {
"data": {
"firstName": "firstName",
"lastName": "lastName"
}
}
}

我想按像 00, 01, 11, 12, final 这样的对象键对这些数据进行排序

我试过这样但我无法实现我想要的。任何想法将不胜感激?

sorted = Object.keys(testData).sort().reduce((acc, key) => ({
...acc, [key]: testData[key]
}), {})

console.log(sorted)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com