Last active
April 18, 2019 10:51
-
-
Save atesztoth/e7087d3128540fa781822226d6ede81a to your computer and use it in GitHub Desktop.
Object traversal JavaScript
This file contains 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 getPropertyDeep = function(rootObject, queryString) { | |
if (queryString.indexOf('.') === -1) return rootObject[queryString] | |
const partialQueryString = queryString.split('.') | |
const partialObject = rootObject[partialQueryString[0]] | |
return getPropertyDeep(partialObject, partialQueryString.slice(1).join('.')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment