Skip to content
loading...

re: Optional Chaining JavaScript / TypeScript VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Nice post @nabinadhikari , I actually made a post about this a while ago here, it might be of use.
 

@pichardoj Ahh, you have a nice approach for this solution. Thank you for pointing to your post, I've learned lot more from your post about optional chaining.

I see a small issue though, what happen if there is "." in property name like {"H.Angel": {"name": "Angel", "location": "Hobart" }}.

This is a normal case in the project I'm currently working on, so I had to take the different approach.

But again, better approach. I couldn't think of it. :)

 

Yeah, that's why I ended using proxies and functions, in order to do something like

optional(obj, obj => obj["H.Angel"].name.location, "Default");
code of conduct - report abuse