Aug 10, 2020 @ 6:35 AM
Aug 22, 2020 @ 10:13 PM
You are probably familiar with this representation of optional chaining:
const nestedProp = obj.first?.second;
The optional chaining operator (
?.) permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid. | Source
You can use optional chaining with objects that use bracket notation.
const nestedProp = obj?.["first"]?.["second"];