How to Use JavaScript Optional Chaining With the Bracket Notation?

Optional chaining with bracket notation object property accessor

You can use optional chaining (?.) with the bracket notation (object property accessor) by adding the ?. symbol before the bracket notation, like so:

// ES11+

For example:

// ES11+
const obj = { 'foo-bar': 123 };

console.log(obj?.['foo-bar']); // 'bar'
console.log(obj?.['non-existent']); // undefined

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