Last active
May 26, 2018 17:45
-
-
Save mohammad-haji/595300c6eb72b50b1633a7d16e7b83cf to your computer and use it in GitHub Desktop.
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
getNestedValue = (data, _key) => { | |
let keys = ("data." + _key).split('.'), | |
nested = keys[0]; | |
for (let i = 1; i < keys.length; i++) { | |
if (eval(nested) == null) { | |
nested = null; | |
break; | |
} | |
nested += "." + keys[i]; | |
} | |
if (nested) { | |
return eval("data." + _key); | |
} | |
return data[_key] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment