score:1

The problem is very simple. Overview.countryData[index] is not defined for the value of index and its value in the if condition is undefined.

But undefined is not the same thing as 'undefined'.

undefined is the value of a missing key in an object or array, the value of a variable that has be unset or not yet set.

'undefined' is a string literal.

No matter how do you compare them (using == or ===), undefined and 'undefined' are never equal.
Because of that, the if condition is always true and it is always taken. But the code in the if branch assumes that Overview.countryData[index] exists (is defined, is not undefined).

The correct test condition is:

if (Overview.countryData[index] != undefined)

You can use, as well:

if (Overview.countryData[index])

because undefined is always evaluated as false in boolean context. The code is more clear this way.


Related Query

More Query from same tag