How to Use JavaScript Optional Chaining With Array?

You can use optional chaining (?.) with an array by adding the ?. symbol before the array index accessor, like so:

// ES11+

For example:

// ES11+
const arr = ['foo', 'bar', 'baz'];

console.log(arr?.[0]); // 'foo'
console.log(arr?.[10]); // undefined

Hope you found this post useful. It was published . Please show your love and support by sharing this post.