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