I have an array of objects with the following structure and I want to extract the property names of the first object from this array without including the values. The desired result should only be
["Name", "Account", "Status"]
.
I attempted the code below, but the output was not what I expected. It includes the index 0 along with the result. Can someone provide guidance on how to achieve the desired outcome?
tempVar = [
{
"Name" : "A1",
"Account" : "Dom",
"Status" : "A"
},
{
"Name" : "A5",
"IntAccount" : "Int",
"Status" : "A"
},
{
"Name" : "A2",
"LclAccount" : "Lcl",
"Status" : "A"
},
{
"Name" : "A4",
"UnknownAccount" : "UA",
"Status" : "A"
}
];
let propNames: Array<any> = [];
tempVar= tempVar.splice(0,1);
for (let el of tempVar)
{
propNames.push(Object.keys(el))
}
console.log(propNames);