我做我的javascript代碼下面的JavaScript數組元素錯誤,同時訪問inspite有檢查
if(
typeof player['stats'] != undefined &&
typeof player['stats']['guild'] != undefined &&
typeof player['stats']['guild']['master'] != undefined &&
typeof player['stats']['guild']['master']['since'] != undefined
)
但是我得到錯誤:
Cannot read property 'since' of null
我一直堅持這樣的而。任何JavaScript大師能幫助我嗎?
刪除'typeof's和'= undefined'部分! –
使用'lodash#get'來簡化這種怪異的構造。 – alexmac
@ibrahimmahrir沒有幫助:(更新:沒有看到你的編輯,讓我再試一次 –