In this example, I have the basic structure of my code:
let myArray: (Array<any> | null);
if (cnd) {
myArray = [];
myArray?.push(elt); // Curious about this line
myArray[0].key = value; // Questioning this line
} else {
myArray = null;
}
Why is the ?
symbol necessary in the line where myArray has already been assigned to an empty array?
Is there a specific syntax to prevent the error message "Object is possibly null" when accessing the key property?
Thank you for your assistance.