Skip to content

Instantly share code, notes, and snippets.

@skydiver
Created September 18, 2019 21:59
Show Gist options
  • Save skydiver/ffcb7d3dcb38839880c3bcbcb9d3fd48 to your computer and use it in GitHub Desktop.
Save skydiver/ffcb7d3dcb38839880c3bcbcb9d3fd48 to your computer and use it in GitHub Desktop.
My JavaScript helpers
const _get = (obj, path, defaultValue = null) =>
String.prototype.split
.call(path, /[,[\].]+?/)
.filter(Boolean)
.reduce(
(a, c) => (Object.hasOwnProperty.call(a, c) ? a[c] : defaultValue),
obj
);
module.exports = { _get };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment