Skip to content

Instantly share code, notes, and snippets.

@cdtinney
Created February 22, 2017 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdtinney/c6dbffc249f4909e6c2f953539219b77 to your computer and use it in GitHub Desktop.
Save cdtinney/c6dbffc249f4909e6c2f953539219b77 to your computer and use it in GitHub Desktop.
Concise pattern for checking existence of nested keys within objects. Credit to http://web.archive.org/web/20161108071447/http://blog.osteele.com/posts/2007/12/cheap-monads/
var level3 = (((test || {}).level1 || {}).level2 || {}).level3;
alert( level3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment