繁体   English   中英

arrays 数组到对象数组

[英]Array of arrays to array of Objects

在此处输入图像描述

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

const events = [
        {
          createdAt: "2021-12-06T16:32:59.260Z"
      funeralId: "0d327e48-b083-4bf5-8dc9-f690c681febd"
    id: "4090aa7e-713b-42b3-a31a-92adb69b9cdb"
    location: "Off-Site"
    name: "Viewing"
    roomId: null
    state: "not_started"
    streamEnd: "2021-12-08T08:14:00.000Z"
    streamId: "Last1638947340"
    streamStart: "2021-12-08T07:09:00.000Z"
    updatedAt: "2021-12-06T16:32:59.260Z"
        },
        {
          createdAt: "2021-12-06T16:32:59.260Z"
      funeralId: "0d327e48-b083-4bf5-8dc9-f690c681febd"
    id: "4090aa7e-713b-42b3-a31a-92adb69b9cdb"
    location: "Off-Site"
    name: "Viewing"
    roomId: null
    state: "not_started"
    streamEnd: "2021-12-08T08:14:00.000Z"
    streamId: "Last1638947340"
    streamStart: "2021-12-08T07:09:00.000Z"
    updatedAt: "2021-12-06T16:32:59.260Z"
        },
    
    ..........
]

如果有人知道请回答

使用Array.flat方法

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

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

您可以使用 Array.flat()

 const events = [ [{ createdAt: "2021-12-06T16:32:59.260Z", funeralId: "0d327e48-b083-4bf5-8dc9-f690c681febd", id: "4090aa7e-713b-42b3-a31a-92adb69b9cdb", location: "Off-Site", name: "Viewing", roomId: null, state: "not_started", streamEnd: "2021-12-08T08:14:00.000Z", streamId: "Last1638947340", streamStart: "2021-12-08T07:09:00.000Z", updatedAt: "2021-12-06T16:32:59.260Z" }], [{ createdAt: "2021-12-06T16:32:59.260Z", funeralId: "0d327e48-b083-4bf5-8dc9-f690c681febd", id: "4090aa7e-713b-42b3-a31a-92adb69b9cdb", location: "Off-Site", name: "Viewing", roomId: null, state: "not_started", streamEnd: "2021-12-08T08:14:00.000Z", streamId: "Last1638947340", streamStart: "2021-12-08T07:09:00.000Z", updatedAt: "2021-12-06T16:32:59.260Z" }] ].flat(); console.log(events)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM