Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda