Last active
March 5, 2018 09:34
-
-
Save c7x43t/ae7c2672fd54555c1a0878c28d211738 to your computer and use it in GitHub Desktop.
ObjectHasKeys - Check for existence of property in deeply nested 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
// Check for existence of property in deeply nested object | |
function get_if_exist(str) { | |
try { return eval(str) } | |
catch(e) { return undefined } | |
} | |
//slightly slower | |
function objHasKeys(obj, keys) { | |
var next = keys.shift(); | |
return obj[next] && (! keys.length || objHasKeys(obj[next], keys)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment