测试JavaScript中是否未定义某些内容 [英] Test if something is not undefined in JavaScript
本文介绍了测试JavaScript中是否未定义某些内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查 if(response [0] .title!== undefined)
,但我收到错误:
I'm checking if(response[0].title !== undefined)
, but I get the error:
Uncaught TypeError:无法读取未定义的属性'title'。
Uncaught TypeError: Cannot read property 'title' of undefined.
推荐答案
response [0]
未定义,检查是否已定义,然后检查其属性标题。
response[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'){
//Do something
}
这篇关于测试JavaScript中是否未定义某些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文