In JavaScript isn't possible to use try
without catch
, but you can simplify it:
javascriptlet obj = { 'name': 'Erik', 'age': 30, 'location': { 'city': 'Barcelona' }, 'height': 177, 'weight': 72 } try{ // Triggering an error on purpose delete obj['friends']['instagram'] } catch{ /* Do nothing */ }
If you are a JavaScript ninja, you can do it in one line of code:
javascripttry{ delete obj['friends']['instagram'] }catch{ /* Do nothing */ }
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.