I have below array of objects.
const array = [{
field1: "val1",
field2: "val2",
field3: {
field1: "val1",
field2: "val2"
}
},
{
field1: "val1",
field2: "val2",
field3: {
field1: "val1"
}
}]
I need to get below output
const output = [{
key: "field1",
subkeys: []
},
{
key: "field2",
subkeys: []
},
{
key: "field3",
subkeys: ["field1", "field2"]
}]
I can get the top level field using this
const keys = array.map(x => Object.keys(x)[0]);
But not able to access the inner ones.
Kindly help... Thanks!!!