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

235
Views
cómo omitir queryselectorall no existe o es nulo
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, }); }

cómo omitir queryselectorall no existe o nulo "characterName": document.querySelectorAll('span.gcharacter')[i].innerText

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

0

Debe verificar si el índice, es decir, i está dentro de los límites de querySelectorAll:

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

0

Debe verificar si el elemento existe, no el innerText . Porque si el elemento no existe, no puede obtener su innerText .

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

0

¿No sería más claro usar un 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 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!