function get(obj,paths){
const keys = paths.split('.');
let current = obj;
for(let key of keys) {
if(typeof current !== 'object' || !(key in current)){
return undefined
}
current = current[key]
}
return current
}
function get1(obj, path, defaultVlue = undefined) {
const pathway = Array.isArray(path) ? path :path.split('.');
return pathway.reduce((acc,key) =>{
if(acc== null){
return defaultValue
}
return acc[key]
},obj)
}
const obj = {
foo: {
bar: {
baz: 'Hello, World!'
}
}
};
console.log(get(obj, 'foo.bar.baz'));
console.log(get(obj, 'foo.bar.qux'));
console