Created
September 18, 2019 21:59
-
-
Save skydiver/ffcb7d3dcb38839880c3bcbcb9d3fd48 to your computer and use it in GitHub Desktop.
My JavaScript helpers
This file contains hidden or 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 _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