I have a nodelist with innerText. I am converting the innerText to an array.
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 ||.
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())
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()