Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda