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

234
Vistas
how to skip queryselectorall does not exist or null
for (i = 0; i < document.querySelectorAll('span.movie-cast-title').length; i++)
{
  if (document.querySelectorAll('span.gcharacter')[i].innerText, == 'null') {
    continue;
  }
  data.actor.push({
    "@type": "PerformanceRole",
    "actor": {
      "@type": "Person",
      "name": document.querySelectorAll('span.movie-cast-title')[i].innerText,
      "url": document.querySelectorAll('a.movie-cast-url')[i].href,
    }
    "characterName": document.querySelectorAll('span.gcharacter')[i].innerText,
  });
}

how to skip queryselectorall does not exist or null "characterName": document.querySelectorAll('span.gcharacter')[i].innerText

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You need to check if the index, that is, i is within the bounds of querySelectorAll:

if(i >= document.querySelectorAll('span.gcharacter').length) {
    continue;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to check if the element exists, not the innerText. Because if the element doesn't exist, you can't get its innerText.

if (!document.querySelectorAll('span.gcharacter')[i]) {
    continue;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

wouldn't it be clearer to use a forEach?

const 
  spCharacters = document.querySelectorAll('span.gcharacter')
, aMovieCast   = document.querySelectorAll('a.movie-cast-url')
  ;
document.querySelectorAll('span.movie-cast-title').forEach( (sp,i) =>
  {
  if (spCharacters[i].innerText !== 'null')
    {
    data.actor.push(
      { '@type' : 'PerformanceRole'
      , 'actor' :
        { '@type' : 'Person'
        , 'name'  : sp.innerText,
        , 'url'   : aMovieCast[i].href,
        }
      , 'characterName': spCharacters[i].innerText
      });
    }
  }
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