Skip to content

Instantly share code, notes, and snippets.

@mohammad-haji
Last active May 26, 2018 17:45
Show Gist options
  • Save mohammad-haji/595300c6eb72b50b1633a7d16e7b83cf to your computer and use it in GitHub Desktop.
Save mohammad-haji/595300c6eb72b50b1633a7d16e7b83cf to your computer and use it in GitHub Desktop.
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