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

118
Views
Do I need to check if an object has a property?

Do I have to check if an object has a specific property when e.g. using a for-loop to access it like:

for(var i = 0; i<array.length< i++) {
  console.log(array1[i].propertyName)
}

If the objects stored in the array differ for some having the specific property and some don't. Should I check it first with obj.hasOwnProperty(prop) or does it return undefined anyway without any conflicts?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can check if the property exists with a simple if statement. As VLAZ pointed out, a missing property will return undefined which in JavaScript is equivalent to false (ey). So you could do:

for(var i = 0; i<array.length< i++) {
  //Will return false if the property doesn't exist
  if(array1[i].properyName != undefined) {
    console.log(array1[i].propertyName)

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