Created
December 5, 2019 20:48
-
-
Save jacopotarantino/318f1d0cc5df5aea70170430f7b1637d to your computer and use it in GitHub Desktop.
safe_read.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
const safe_read = (object, property) => { | |
try { | |
return property.split('.').reduce((acc, current) => {return acc[current] || undefined}, object) | |
} catch(e) { | |
return null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment