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

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

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