Raimonds Raimonds - 1 year ago 79
Javascript Question

Test if something is not undefined in JavaScript

I'm checking

if(response[0].title !== undefined)
, but I get the error:

Uncaught TypeError: Cannot read property 'title' of undefined.

Answer Source

reponse[0] is not defined, check if it is defined and then check for its property title.

if(typeof response[0] !== 'undefined' && typeof response[0].title !== 'undefined'){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download