Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Created December 5, 2019 20:48
Show Gist options
  • Save jacopotarantino/318f1d0cc5df5aea70170430f7b1637d to your computer and use it in GitHub Desktop.
Save jacopotarantino/318f1d0cc5df5aea70170430f7b1637d to your computer and use it in GitHub Desktop.
safe_read.js
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