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

125
Visualizações
Index variable of an array in a for loop throwing error

I want to compare the start date of the curr_item array based on index, but im getting this particular error at the arrow marked line.Im not sure what the issue is :(

0: Object start_time: "2021-10-27T13:30:00.000+05:30" end_time: "2021-10-27T13:45:00.000+05:30" 1: Object start_time: "2021-10-27T13:46:00.000+05:30" end_time: "2021-10-27T14:00:00.000+05:30" 2: Object start_time: "2021-10-27T14:00:00.000+05:30" end_time: "2021-10-27T15:02:00.000+05:30"


for (let index = 0; index < possible_slots; index++) {
  if (
    curr_time.toMillis() ===
   -----> DateTime.fromISO(curr_item[index].start_time).toMillis() <-----
  ) {
    slotlist.push({
      start_time: DateTime.fromISO(curr_item[index].start_time).toISO(),
      end_time: DateTime.fromISO(curr_item[index].end_time).toISO(),
      name: `asd`
    });
  } else {
    slotlist.push({
      start_time: DateTime.fromISO((curr_item[index]).start_time).toISO(),
      end_time: DateTime.fromISO(curr_item[index].end_time).toISO(),
      hole: `true${index}`
    });

    curr_time = DateTime.fromISO(slotlist[slotlist.length - 1].end_time);
  }
  curr_item[index] = curr_item[index + 1];
}

Error: Cannot read properties of undefined (reading 'start_time')

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

0

There can be only two reasons for this:

  1. Array which is according to your code curr_item is undefined. 2.The index you are trying to access inside the curr_item array is not available in the array. meaning curr_item[index] gives undefined and when you try to access the start_time of the above statement it throws the error.
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