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

171
Visualizações
array in callback for reduce is not an array?

I have a callback that I am using like

return innerArray.reduce((prev, curr, i, array) => {

However, when I try to use the array (for me this is an array of objects) like

array[i-1].outerIndex

I get a JavaScript error that I cannot read a property of undefined, reading outerIndex. The only way I was able to get this to work is with

let prevObj = { ...array[i - 1] };
prevObj.outerIndex

Is there something that is not an array in the argument passed to the reduce callback?

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

0

Is there something that is not an array in the argument passed to the reduce callback?

No. It is an array.

The error message says that array[i-1] is undefined.

This is probably when it is dealing with the first item in the array so i is 0 so you are trying to access array[-1] which is out of bounds.

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