Skip to content

Instantly share code, notes, and snippets.

@c7x43t
Last active March 5, 2018 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7x43t/ae7c2672fd54555c1a0878c28d211738 to your computer and use it in GitHub Desktop.
Save c7x43t/ae7c2672fd54555c1a0878c28d211738 to your computer and use it in GitHub Desktop.
ObjectHasKeys - Check for existence of property in deeply nested object
// 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