Skip to content

Instantly share code, notes, and snippets.

@serweb-labs
Created August 2, 2018 04:12
Show Gist options
  • Save serweb-labs/7e392216d08b9f0dee95fd42d1cd381e to your computer and use it in GitHub Desktop.
Save serweb-labs/7e392216d08b9f0dee95fd42d1cd381e to your computer and use it in GitHub Desktop.
safe get attribute
function getAttr(o, p, d) {
if (!Array.isArray(p)) { p = p.split("."); }
var def = (d === null) ? null : (d || false);
return p.reduce((xs, x) => (xs && xs[x] !== undefined) ? xs[x] : def, o)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment