const foo = {
bar: {
baz: true
}
}
dotObj('foo.bar.baz', foo); // true
Last active
December 7, 2024 21:08
-
-
Save nblackburn/83d53cf170e9a8d4b6dc6862f9c7a3e3 to your computer and use it in GitHub Desktop.
dotObj
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 dotObj = (path, data, delimiter = '.') => { | |
const slices = path.split(delimiter); | |
return slices.reduce((a, v) => a = data[v], data); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment