Last active
August 29, 2015 13:56
-
-
Save dhoko/9231111 to your computer and use it in GitHub Desktop.
Get value from an object from a path inside the object
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
/** | |
* Get a value from an object by its path | |
* @param {Object} obj | |
* @param {String} path Path to the value key1.key2.key3... | |
* @return {Object} Value | |
*/ | |
function valuePathObject(obj, path) { | |
path.split(".").forEach(function(item){ | |
obj = obj[item] | |
}); | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemple :