【发布时间】:2022-01-06 04:52:59
【问题描述】:
我有两个长度相同的对象,每个 ID 都有一个公共属性 edge_id。我想将第二个对象添加到第一个对象的属性中。
我有一个 MapLibre 地图,我想添加一些来自 API(第二个对象)的属性。
第一个对象
[
{
"type": "Feature",
"properties": {
"edge_id": 67135,
"color": "#f7fabf"
},
"geometry": {
"type": "Polygon",
"coordinates": [ ]
}
},
{
"type": "Feature",
"properties": {
"edge_id": 15984,
"color": "#fcd6a4"
},
"geometry": {
"type": "Polygon",
"coordinates": [ ]
}
},
]
第二个对象
[
{
"edge_id": 67135,
"name": "R12",
"length": 0.14907826598895346,
"speed": null,
"lanes": null
},
{
"edge_id": 15984,
"name": "Pont de Sully",
"length": 0.01577450403315043,
"speed": 30,
"lanes": 2
},
]
我想要edge_id : 67135 的以下输出:
{
"type": "Feature",
"properties": {
"edge_id": 67135,
"color": "#f7fabf",
"name": "R12",
"length": 0.14907826598895346,
"speed": null,
"lanes": null
},
"geometry": {
"type": "Polygon",
"coordinates": [ ]
}
},
【问题讨论】:
-
我不明白你想要什么样的结果,你能用两个对象开始重构你的问题吗?你想要什么样的最终输出
-
@Frenchy,第一个例子是我想要的输出
标签: javascript arrays object