嘿,我在 Polygons.js 中找到了这个对象:
var polygons = [
{
"_id" : "12345",
"geometry" : {
"coordinates" : [[
[9.123553, 48.71568],
[ 9.119548, 48.71526 ]
]]
}
},
{
"_id" : "67890",
"geometry" : {
"coordinates" : [[
[ 9.090445, 48.715736 ],
[ 9.089583, 48.715687 ]
]]
}
}
]
我想循环遍历这个数组以获得如下的结果:
[
{
"_id" : "12345",
"coordinates" : [[
[9.123553, 48.71568],
[ 9.119548, 48.71526 ]
]]
},
{
"_id" : "67890",
"coordinates" : [[
[ 9.090445, 48.715736 ],
[ 9.089583, 48.715687 ]
]]
}
]
有人知道如何解决吗? 非常感谢您的关注!
最佳答案
您可以映射数组并进行所需的更改
formatted_polygons = polygons.map(function(polygon){
return {
coordinates : polygon.geometry.coordinates,
_id : polygon._id
}
});
关于javascript - Node.js 中的循环多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52524615/