Skip to content

Instantly share code, notes, and snippets.

@YannickLeRoux
Created March 8, 2019 00:07
Show Gist options
  • Save YannickLeRoux/66180e4e0659c5d563f740998453075c to your computer and use it in GitHub Desktop.
Save YannickLeRoux/66180e4e0659c5d563f740998453075c to your computer and use it in GitHub Desktop.
Chech if nested property exist in object
function checkNested(obj /*, level1, level2, ... levelN*/) {
var args = Array.prototype.slice.call(arguments, 1);
for (var i = 0; i < args.length; i++) {
if (!obj || !obj.hasOwnProperty(args[i])) {
return false;
}
obj = obj[args[i]];
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment