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

388
Views
Check if all values in my array equals specific text

I'm new to javascript. I created the following code to check if a specific value exists in an array and then show text based on whether the value exists or not:

// Get my div
ar mydiv = document.querySelector("#mydiv");

// Create Array
var mylist =  Array.from(document.getElementsByClassName('myitem'), e => e.innerText)

// Check if value exist
myanswer = mylist.includes("None");

// Output Text
if (myanswer == true) {
    mydiv.textContent = "True in list";
} else {
    mydiv.textContent = "False in list";
}

It works well, but now I want to change it so that it checks weather ALL values in my array equals "None".

I changed the following line:

myanswer = mylist.includes("None");

To be this instead:

myanswer = mylist.every.equals("None");

This doesn't work though, so how is the best way to go about doing this?

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

0

In your case, MyList.every is a function not a single element.

What you want instead is checking if every element is equals to None.

Then The good way of doing it is the following :

myList.every(elem => elem === 'None')

This will return true if all elems are equals to None, false otherwise


Here is a small example with an array of string where you want to check if every item is 'None'

const arr1 = ['None','None','None','None','Not None']
const arr2 = ['None','None','None','None','None']

console.log(arr1.every(elem => elem === 'None'))
console.log(arr2.every(elem => elem === 'None'))

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!