Skip to content

Instantly share code, notes, and snippets.

@vibhasbhingarde
Last active June 8, 2018 04:10
Show Gist options
  • Save vibhasbhingarde/a8a71f24fc832f1f77e912e2cd944295 to your computer and use it in GitHub Desktop.
Save vibhasbhingarde/a8a71f24fc832f1f77e912e2cd944295 to your computer and use it in GitHub Desktop.
// Check if nested property exists or not
var propertyexists = (objectname,path) => path.split(".").reduce((k,v) => (typeof k=="undefined")?k:k[v],objectname);
var myobject = {info:{name:"vibhas"}};
console.log(propertyexists(myobject,"info.name.jhgfdsa.asdfghj"));
// If exists it return that value or "undefined"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment