-
-
Save Om4ar/40af6dae67398f7bb6593a8a6f625818 to your computer and use it in GitHub Desktop.
access nested variables and passing of undefined error in js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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