Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda