I am trying to access a certain member in a JavaScript object. In order to do this, I need to try out a couple of key values.
For example, Object['text/html']
which will give me an export link for a HTML document. However, not every object of this type will have a text/html
key pair value.
In Python I would solve this problem using a Try-Catch block, with the KeyError
exception. If I can do something similar in javascript, as in use an exception in a Try-Catch block, that would be great.
However, if alternatives exists instead of try catch blocks, that do achieve the same end goal, I would like to know about them as well.
EDIT:
I would prefer to use an exception over using functions. I do this because the text/html
key might not be there, but it should be there. An exception seems more appropriate for this scenario