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

134
Views
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 answers
Answer question

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 Report

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 Report

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 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!