You can use optional chaining (?.) with an array by adding the ?. symbol before the array index accessor, like so:
// ES11+
array?.[index]
For example:
// ES11+
const arr = ['foo', 'bar', 'baz'];
console.log(arr?.[0]); // 'foo'
console.log(arr?.[10]); // undefined