【发布时间】:2025-12-15 00:00:02
【问题描述】:
我有以下包含对象数组的数组。
const arr = [
[
{
"key1": "keyName",
"key2": "test name1"
},
{
"key1": "keyDescription",
"key2": "test description1"
}
],
[
{
"key1": "keyName",
"key2": "test name2"
},
{
"key1": "keyDescription",
"key2": "test description2"
}
]
]
我需要的结果如下。
result = [
{
"key_name": "test name1",
"key_description": "test description1"
},
{
"key_name": "test name2",
"key_description": "test description2"
}
]
我使用 js 'map' 和 'find' 方法尝试过这个,但它给出了错误的格式。
const res = arr.map(i => i.find(j => j.setting_code === "hotelRate")).map(k => k.setting_value)
我听说这可以使用“减少”来完成。我将不胜感激。谢谢!
【问题讨论】:
-
请在发布问题之前投入更多时间来校对您的问题。发布版本 A,然后添加另一个要求,在已有答案之后添加相当多的额外任务,这不是“最好”的方式......
标签: javascript arrays sorting object format