Last active
March 4, 2018 21:10
-
-
Save Om4ar/3db2de3bf978717e92b4e34981bc60c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // array , property string | |
| // https://medium.com/javascript-inside/safely-accessing-deeply-nested-values-in-javascript-99bf72a0855a | |
| const get = (p, o) => | |
| p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o) | |
| // let's pass in our props object... | |
| console.log(get(['user', 'posts', 0, 'comments'], props)) | |
| // [ 'Good one!', 'Interesting...' ] | |
| console.log(get(['user', 'post', 0, 'comments'], props)) | |
| // null | |
| export const isEmpty = value => | |
| value === null || | |
| value === undefined || | |
| value === "undefined" || | |
| value.length === 0 || | |
| value === {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment