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

135
Visualizações
how can i read a property of an object in javascript
objects [ {
    firstName: "Kristian",
    lastName: "Vos",
    number: "unknown",
    likes: ["JavaScript", "Gaming", "Foxes"],
    }....]

if this is my object, i need to read the word "firstName" and not the value of "firstName"

i know how to output the value of firstName ( objects[0].fisrtName ) = "Kristian"

but what i really need to read is if the object has a property called firstName, in case that the object doesnt have that property.

thanks

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can check

Object.keys(objects[0])

Or you can just check it like that

if ('firstName' in objects[0]) {
  // ...
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can achieved this using Object.keys():

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

about 4 years ago · Juan Pablo Isaza Relatório

0

I think you code isn't actually object since you use [ ], it is more likely an array contain object.

This code should work, if you mistype the [ ], just use Object.keys(test)[0] instead.

let test = [{
  firstName: "Kristian",
  lastName: "Vos",
  number: "unknown",
  likes: ["JavaScript", "Gaming", "Foxes"]
}]
console.log(Object.keys(test[0])[0])

about 4 years ago · Juan Pablo Isaza 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