Cannot read property 'xxxx' of undefined

0👍

In the second line of your code you take the first element out of the „data“ Array.
If the Array is empty or undefinded then there is no first element of which you can take the attribute „dateHisto“.

So you might add in the first line of the function to check if you received any input.

if(!data || data.length < 1){
  return
}

The BEST (!) way would be to check if there is any input before (!) you call the function.

👍:0

2 Options:

No. 1:

The data.dateHisto on the following line: var date = new Date(data.dateHisto); is undefined

No. 2:

The resultW on the following code:

var resultW = dataH.filter(function(data) {
    var date = new Date(data.dateHisto);
    return date.getWeek() == k;
});

is an array which contains a single or more elements without dateHisto property, or contains it but its value is undefined

Leave a comment