【问题标题】:Array of arrays to array of Objects数组数组到对象数组
【发布时间】:2022-01-24 21:45:04
【问题描述】:
const events = [
        [{
          createdAt: "2021-12-06T16:32:59.260Z"
    location: "Off-Site"
    name: "Viewing"
        }],
        [{
          createdAt: "2021-12-06T16:32:59.260Z"

... }],

    ..........
]

您好,我有问题。从上面我可以将数据转换为类似的东西

const events = [
        {
          createdAt: "2021-12-06T16:32:59.260Z"
    location: "Off-Site"
        },
        {
          createdAt: "2021-12-06T16:32:59.260Z"

... },

    ..........
]

谁知道请回答

【问题讨论】:

    标签: javascript arrays reactjs json object


    【解决方案1】:

    使用Array.flat方法

    flat() 方法创建一个新数组,其中所有子数组元素递归连接到指定的部门

    const arr = [[1,2,3],[4,5]];
    
    const res = arr.flat()
    
    console.log(res)

    【讨论】:

      猜你喜欢
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多