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

234
Views
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 answers
Answer question

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 Report

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 Report

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