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

239
Views
Why does Array.find() produce this result?

I have this:

const array1 = [12, 5, 8, 130, 44];

var check = array1.find((element, b) => b);

console.log(check);

Output is coming as 5 rather than 12 why?

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

0

find returns the first item that satisfies the condition in the callback. You are returning b, which is the index. The returned result is the second item since the first item's index is 0, which is falsy. The second index is 1, which is truthy.

about 4 years ago · Juan Pablo Isaza Report

0

The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(n=>n>20); console.log(found);

this will return 130 because n is greater than 20 we specified here

const array1 = [3,4,5,8,1]

const found = array1.find(n=>n>3)

will return 4

this will be correct one

const array1 = [12,5,8, 130, 44];

var check=array1.find(b => b>10 ); console.log(check);

and the error is because you are not targeting the correct element

The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

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!