Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda