Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
How to retrieve first object's property names of an object array?

I have an object array with below structure and I need to get first object's property names alone from this array and not values. My result should only have ["Name" , "Account", "Status"].

I tried below lines of code but the result was not as expected. I am getting the result along with index 0. Can someone guide me here to achieve the result.

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);
about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

You're overcomplicating it.

To get the first element, index tempVar with square brackets: tempVar[0].

Then, to get the keys, just call Object.keys() on it:

const propNames = Object.keys(tempVar[0]);
about 4 years ago · Santiago Gelvez Report

0

Try the following lines of code:

let propNames: Array<any> = [];
tempVar= tempVar.splice(0,1);
for (let key in tempVar) 
{
  propNames.push(key)
}
console.log(propNames);
about 4 years ago · Santiago Gelvez Report

0

Try this.

let propNames: Array<any> = [];
for (const key of Object.keys(tempVar[0])) {
  propNames.push(key)
}
console.log(propNames);
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!