我想在 branches 数组中搜索 finder 对象,如果找到匹配项,那么我想获取 finder 对象的位置名称。
var branches= [
{
locationName: "Cool Towers",
coordinates: [
{
latitude: 25.33853805869942,
longitude: 55.393801012135796,
},
{
latitude: 25.33848836326937,
longitude: 55.393874772883706,
},
{
latitude: 25.338230189121408,
longitude: 55.39362935075884,
}
],
},
{
locationName:"Great Towers",
coordinates: [
{
latitude: 25.16626719853835,
longitude: 55.26170584184425,
},
{
latitude: 25.166607063076132,
longitude: 55.26206257564323,
}
],
}
]
var finder =
{
latitude: 25.166607063076132,
longitude: 55.26206257564323,
}
本案例预期结果为:Great Towers
这就是我尝试过的。但这总是给我第一个位置名称
const filter = Object.entries(finder),
result = branches
.filter(({ coordinates }) =>
filt.every(([key, value]) => coordinates[key] === value)
)
.map(({ locationName }) => locationName);
胡说叔叔
皈依舞
料青山看我应如是
忽然笑
相关分类