I have one problem statement.
Implement a function propertyExists(obj, path) that takes in an object and a path (string) as arguments and returns ‘False’ if the property doesn’t exist on that object or is null, else returns the value of the property.
And here is solution.
function propertyExists(obj,path) {
// Write logic here
let result = obj.hasOwnProperty(path);
if(result)
{
return (obj.path);
}
else
{
return result;
}
}
Is this correct way of doing it?
header.customer.address.lines[0]etc. But then your have called itpropertyExists, so its likely property anyway, so not sure why its notpropertyExists(obj, property)You likely wantreturn obj[path]too.if (obj[path] === undefined || obj[path] === null) { return false; } else { return obj[path]; }