【发布时间】:2012-01-18 19:39:32
【问题描述】:
我需要将 imagesrc 替换为该对象中存储的值。但是当我运行时:
if(data['results'][res]['entities']['media']["0"]["media_url"]) {
imagesrc = data['results'][res]['entities']['media']["0"]["media_url"];
}
我得到错误:
Cannot read property '0' of undefined
如何运行我的条件,以便在某些未定义的情况下不会出错?
【问题讨论】:
-
先检查是否未定义:stackoverflow.com/questions/776950/…
-
您考虑过使用 try..catch 吗?
标签: javascript