vibhasbhingarde
6/8/2018 - 4:03 AM

Nested property exists or not

// 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"