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

215
Visualizações
Uncaught TypeError despite undefined check

I am getting this error.

I am trying to filter by time of day, and I'm receiving the inputs from two HTML time fields.

export function timeBetweenFilterFn(rows, id, filterValues) {
const startVals = filterValues[0] ? filterValues[0].split(':') : undefined;
const endVals = filterValues[1] ? filterValues[1].split(':') : undefined;


const [startHour, startMinutes] = startVals ? 
        startVals.map( (val) => {
            return parseInt(val);
        })
        : undefined;
const [endHour, endMinutes] = endVals ? 
        endVals.map( (val) => {
            return parseInt(val);
        })
        : undefined;

if (startVals || endVals) {
    return rows.filter( (row) => {
        const [cellHour, cellMinutes] = row.values[id].split(':').map( (val) => {
            return parseInt(val);
        })
        if (cellHour === startHour){
            return cellMinutes >= startMinutes;
        }
        else if(cellHour === endHour){
            return cellMinutes <= endMinutes;
        }
        else{
            return cellHour >= startHour && cellHour <= endHour;
        }

    })
}
return rows;

}

when either the start field or end field is not given, I get the uncaught type error when I try to map the array to the new values despite the ternary check.

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

0

If you use undefined as the fallback value, you will get an error cause you are trying to get variables [startHour, startMinutes] and [endHour, endMinutes] from undefined, which is not iterable.


You can't try to get variables from undefined.

As you can see in this example made in the browser console, i get the same error, because undefined is not iterable.

enter image description here

Instead of undefined, try using [] as default value in order to avoid errors.

enter image description here

In this case the variables a and b will simply be 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