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

102
Views
How to make every single value of array suitable in IF statement?

For example i have an array with 100 values, let it be a[1,2,3...100]
Can I create a if check that will be suitable for any value from the array?
like:

if(value === a[any index]){
//do smth
}

almost sure that it can be done but don't know how, can you help me with that?

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

0

You can use forEach:

a.forEach(element => {
  if (value === element) {
    // do something
  }
});
about 4 years ago · Juan Pablo Isaza Report

0

// for of
for (const item of a) {
  if (value === item) {

  }
}

// traditional for loop
for (let i = 0; i < a.length; i++) {
  if (value === array[i]) {

  }
}

// forEach
a.forEach(item => {
  if (value === array[i]) {

  }
});
about 4 years ago · Juan Pablo Isaza Report

0

You should use the ES7 array.includes(). If it finds a given value in your array it will return a True boolean, else it will return False.

Example:

console.log([1,2,3].includes(2)) //True

console.log([1,2,3,4,5].includes(6)) //False

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!