Test if something is not undefined in JavaScript

前端 未结 11 1831
礼貌的吻别
礼貌的吻别 2020-11-30 19:50

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

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

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 19:58

    You must first check whether response[0] is undefined, and only if it's not, check for the rest. That means that in your case, response[0] is undefined.

提交回复
热议问题