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

87
Views
Javascript find function

I have an array and trying to use find method and it doesnt give be expected result but i get it via foreach. Sorry I cann't provide array, because i dont have it . I tried for a long time but didn't find a mistake. Hope its enough.

When i am using that foreach it works

products.product.forEach(function(p) {
  p.composition.id === id);
} 

But it doesnt work here

let currentProduct = products.product.find(pr=> {pr.composition.id===id});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The reason it's not working is because you're not returning the boolean of the condition from the .find. Try this:

let currentProduct = products.product.find((pr) => {
    return pr.composition.id === id;
});

Or even just without the curly braces:

let currentProduct = products.product.find((pr) => pr.composition.id === id);
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!