Reputation: 1429
I have the following simple literal object:
const ob = { 'xxx:': 'abc', aaaa: 3, ccc: [1, 2, 3] };
let's say i'm not sure that i have a ccc key in the object so i want to use Optional Chaining but i'm getting a syntax error when trying to run:
const ddd = ob.ccc?.[0];
What is the correct syntax that takes the value only if *ccc key exist?
Upvotes: 0
Views: 1210
Reputation: 21371
As Quentin said, the Optional chaining operator doesn't support the legacy version Microsoft Edge(Edge Html 12~18, the Microsoft Edge 44.18362.449.0 using Microsoft EdgeHTML 18.18363). More detail information, you could check the following links:
The optional chaining operator Browser compatibility
JavaScript operator: Optional chaining operator
To use the Optional chaining operator, you have to use the new Microsoft Edge, and upgrade the Microsoft Edge browser Version to 80+ version. You can download the latest version Microsoft Edge from here.
Reference: EdgeHtml
Upvotes: 1