我从后端获取数据,数据是JSON格式并嵌套,如
[{
a: {
b: {
c: 'value',
...
},
...
}
},....]
或者
[{
a: {
b: {
// no key 'c'
...
},
...
}
},....]
也可能是
[{
a: {
// no key 'b'
...
}
},....]
我必须安全地获得'a.b.c',有什么好办法吗?
'A.B.C.D'?
答案 0 :(得分:0)
您可以像这样使用hasOwnProperty()
if(a.hasOwnProperty('b')){
console.log(a.b);
}