Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Meet condition from multiple text values in nodelist of a querySelectorAll

I have a nodelist with innerText. I am converting the innerText to an array.

Screen-shot of the nodelist:

Screen-shot of the nodelist

Below is my code:

var fltarr = []
for( z=0; z<document.querySelectorAll("div.flight-number").length; z++){
fltarr.push(document.querySelectorAll("div.flight-number")[z].innerText)
}

Now I am creating the if conditions as below but instead of using or || statement, is there another way to use for example coma separated etc to keep the code cleaner and not to clutter with too many ||.

Conditions for fltarr

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You mean

[...document.querySelectorAll("div.flight-number")]
  .filter(div => ["NH 98","NH 96"].includes(div.textContent.trim())

Easier to answer if you post actual HTML and what you want as output

Here are all the divs content

[...document.querySelectorAll("div.flight-number")]
  .map(div => div.textContent.trim())
about 4 years ago · Juan Pablo Isaza Relatório

0

You can create an array of values you & use every to check if the values exist like this

var valuesToCheck = ['NH 96', 'NH 98']
flatarr.every(i => valuesToCheck.includes(i))
about 4 years ago · Juan Pablo Isaza Relatório

0

You can try with Array.prototype.some()

var flatarr= Array.from(document.querySelectorAll("div.flight-number")).map(el => el.textContent);
console.log(flatarr.some(i => ['NH 96', 'NH 98'].includes(i)))
// BY USING REGEX
console.log(flatarr.some(i => i.match(/^NH\s9[8|6]$/g)))
<div class="flight-number">NH 96</div>
<div class="flight-number">EY 871</div>
<div class="flight-number">NH 97</div>

For every match, try using Array.prototype.every()

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda