【发布时间】:2019-11-26 12:19:26
【问题描述】:
基本上,我想使用 Javascript(最好是 ES6)在对象内部展平一个数组。我实际上不确定这是否甚至是扁平化的问题,我只是想要一个很好的方法来进行这种更改。
我想从这里开始:
{
id: "123",
name: "test",
history: [
{
id: "456",
name: "test2"
},
{
id: "789",
name: "test3"
}
]
}
到这里……
{
id: "123",
name: "test"
},
{
id: "456",
name: "test2"
},
{
id: "789",
name: "test3"
}
基本上在原始对象中,我有一个与该特定对象相关的“历史”属性。有什么想法吗?
【问题讨论】:
-
能否请您附上您解决此问题的尝试?
-
生成的结构无效
-
history中的对象本身可以有history数组吗?换句话说,这可以无限嵌套吗?
标签: javascript arrays json object flatten