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

122
Views
¿Necesito verificar si un objeto tiene una propiedad?

¿Tengo que verificar si un objeto tiene una propiedad específica cuando, por ejemplo, uso un bucle for para acceder a él como:

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

Si los objetos almacenados en la matriz difieren en que algunos tienen la propiedad específica y otros no. ¿Debería verificarlo primero con obj.hasOwnProperty(prop) o de todos modos devuelve indefinido sin ningún conflicto?

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

0

Puede verificar si la propiedad existe con una declaración if simple. Como señaló VLAZ, una propiedad faltante devolverá undefined que en JavaScript es equivalente a false (ey). Así que podrías hacer:

 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!