Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda