You can use optional chaining (
?.) with an array by adding the
?. symbol before the array index accessor, like so:
// ES11+ array?.[index]
// ES11+ const arr = ['foo', 'bar', 'baz']; console.log(arr?.); // 'foo' console.log(arr?.); // undefined
Hope you found this post useful. It was published . Please show your love and support by sharing this post.