Skip to content

Instantly share code, notes, and snippets.

@trmaphi
Created August 19, 2019 07:34
Show Gist options
  • Save trmaphi/f6cc5684414bcb973aa7cc469280d108 to your computer and use it in GitHub Desktop.
Save trmaphi/f6cc5684414bcb973aa7cc469280d108 to your computer and use it in GitHub Desktop.
Safely get a nested property of an object in Javascript
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment