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

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

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 Denunciar

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 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