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

174
Visualizações
Array.find() gives error "TypeError: theArray.find(...) is undefined"

I'm getting TypeError: theArray.find(...) is undefined from a code that is in essence similar to this:

if (!Array.isArray(theArray)) console.error("WARNING! theArray is not an array: ", theArray);
console.log(theArray.find((element) => element).someProperty);

I'm not getting the error message WARNING! theArray is not an array, but I'm getting the error theArray.find(...) is undefined

The error message does not say that theArray is undefined, this is an error message that I would except when theArray is not of type array.

Inside the array function there would be a more complex logic, but I simlified it to focus on the Array.find() problem. The variable theArray is an array of complex objects, with a lot of properties.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Array.find will return undefined when it does not find a result.

The error message means that find() function returned undefined, then someProperty can not be found on undefined.

Example for clarification:

let testArray = [{a: 3}, {a: 4}, {a: 5}];
let notArray = 5;

testArray.find((item) => item.a === 3); will result Object { a: 3 }
tetArray.find((item) => item.a === 3); will result Uncaught ReferenceError: tetArray is not defined
notArray.find((item) => item.a === 3); will result Uncaught TypeError: notArray.find is not a function
testArray.find((item) => item.a === 7).a; will result Uncaught TypeError: testArray.find(...) is undefined

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