包括但不限于中间有一层的值是null或undefined,或者中间某层是数组,一个一个if下去感觉有点麻烦,而且字符串型要判断 ''、null、undefined
有呀 可选链const res = a?.b?.c?.d?.e就是兼容性要求比较高如果你是babel7以上 可以用插件支持 @babel/plugin-proposal-optional-chaining
const res = a?.b?.c?.d?.e
babel7
@babel/plugin-proposal-optional-chaining
1.4m articles
1.4m replys
5 comments
56.7k users