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

128
Views
how to compare every element in array to a value

What I essantily want to do is compare all values in array to 123 in an if statment

let values = [1, 2, 3, 123]
if (123 == values.forEach(e => {return e})){

currently, I'm getting an error:

values.forEach(e => {return e})) is not a function

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

0

If i understand that you want, try something like this

let values = [1, 2, 3, 123]

if (values.includes(123)) {
   *do some code*
}
about 4 years ago · Juan Pablo Isaza Report

0

const array1 = [1,2,123,123];

array1.forEach(element => element === 123 && console.log(element));

about 4 years ago · Juan Pablo Isaza Report

0

You can use array.indexOf() function to check whether 123 is present in the array or not :

let values = [1, 2, 3, 123]

    if (values.indexOf(123)!=-1) {
       ...write code    
    }

let values = [1, 2, 3, 123]

if (values.indexOf(123)!=-1) {
   console.log("123 is present");
}else {
  console.log("123 is not present");
}

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!