js嵌套對象報錯Uncaught TypeError: Cannot read property 'name' of undefined at解決方法


const user = { name:{ age:12 } }

我們打印

console.log(user.name1.age)

會報錯Uncaught TypeError: Cannot read property 'name1' of undefined     at

這時:console.log(((user||{}).name1||{}).age)就不會報錯,打印出undefined

這種對於嵌套對象比較適合,但數組不是很好

具體可參考:https://www.javascriptc.com/3457.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 TypeError: Cannot read property 'parseComponent' of undefined 報錯解決方法 js 報錯 Uncaught TypeError: Cannot read property 'trim' of undefined 顯示 Uncaught TypeError: Cannot read property 'dialog' of undefined”的錯誤解決方法 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'name' of undefined 報錯誤 : ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'name' of undefined Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解決方法 Vue報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解決方法 TypeError: Cannot read property 'xxxx' of undefined的解決方法 TypeError: Cannot read property 'xxxx' of undefined的解決方法 bootstrap table 報錯 Uncaught TypeError: Cannot read property 'colspan' of undefined
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM