Skip to content

Instantly share code, notes, and snippets.

@Om4ar
Last active February 8, 2018 12:14
Show Gist options
  • Save Om4ar/40af6dae67398f7bb6593a8a6f625818 to your computer and use it in GitHub Desktop.
Save Om4ar/40af6dae67398f7bb6593a8a6f625818 to your computer and use it in GitHub Desktop.
access nested variables and passing of undefined error in js
// check for empty objects/variables
isEmpty = value =>
value === null ||
value === undefined ||
value === "undefined" ||
value.length === 0 ||
value === {};
// access the nested variables or return null if undifined or doesn't exist
getNested = (p, o) => p.reduce((xs, x) => (!this.isEmpty(xs) && !this.isEmpty(xs[x]) ? xs[x] : null), o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment