Optional Chaining Array and Three orders
Closed this issue · 2 comments
120011676 commented
obj?.prop // 自判断静态属性访问
obj?.[expr] // 自判断动态访问
func?.(...args) // 自判断函数或方法调用
arr Arrary
error
arr?
arr Arrary
error
arr?[0]?
arr Arrary
error
(arr?[0]?.bol?)?"a":"b"
console.log(getFieldValue('msid')?[0]?.batchs)
claudepache commented
Hi,
It is not clear what you are trying to say, but trying to guess:.
- You cannot use
arr?[0]
. If you expect thatarr
is sometimes null or undefined,
usearr?.[0]
. If you know thatarr
is never null or undefined, usearr[0]
. - You cannot use
foo?
. If you are trying to test whetherfoo
is neither null nor undefined,
usefoo != null
.
120011676 commented
@claudepache Good,Confirmed