I am looking to extract a list of unique keys from an array of objects.
arr =[
{id: 1, desc: "", name: "", objectives: Array(3), …},
{id: 2, desc: "", name: "", objectives: Array(3), …},
{id: 3, desc: "", name: "", objectives: Array(3), …},
{id: 4, desc: "", name: "", objectives: Array(3), …},
]
The desired output should be [id, desc, name, objectives]. I have attempted the following approaches:
Object.keys(arr)[0]
// output [{id: 1, desc: "", name: "", objectives: Array(3), …}]
arr.flatMap(Object.key)
// output ["id", "desc", "name", "objectives", "id", "desc", "name", "objectives", "id", "desc", "name", "objectives", "id", "desc", "name", "objectives"]
I apologize if I might have overlooked the answer to this while searching on SO. Any assistance would be greatly appreciated.