javascript - Node.js 中的循环多维数组

标签 javascript node.js multidimensional-array ecmascript-6

嘿,我在 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/

相关文章:

javascript - 在 ASP.NET MVC 4 View 中将数据从父窗口传递到弹出(子)窗口

javascript - 对 HTML 表列中的每个单元格执行 X?

node.js - Nodejs 和 Socket.io 中的实时协作文本编辑器

c - 如何在 C 函数中传递二维数组(矩阵)?

C 二维数组

javascript - 如何替换 REACT.js 中的 refs(antd 表示例)

node.js - 如何使用express设置iisnode?

javascript - 不变违规 : Usage Issue for npm Library

Python - 在 2D numpy 数组中查找特定值的最大面积的有效方法

javascript - 交换div在某个索引处的位置