Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!