I have data like so:
data = [
{
"foo": {"name":"foo-name"},
"bar": {"name":"bar-name"}
},
{
"baz": {"name":"baz-name"}
}
]
and my desired output would be:
[
{ "foo": {"name":"foo-name"}},
{ "bar": {"name":"bar-name"}},
{ "baz": {"name":"baz-name"}}
]
How do I get this structure? I tried using concat, but realized that it doesn't work as we are dealing with nested objects and not nested arrays. Then I tried iterating in different ways, but not achieving what I want. One try was the following:
const newData = data.map((x) => {
return Object.keys(x).map(el => {
return {[el]: x};
})
})
But that just made it more nested.