SOURCE

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
}

const obj = { 
  foo: {
    bar: {
      baz: 'Hello, World!'
    }
  }
};

// set(obj, 'foo.bar.baz', 'New Value');
console.log(get(obj, 'foo.bar.baz')); // Output: New Value

console.log(get(obj, 'foo.bar.qux')); // Output: undefined
console 命令行工具 X clear

                    
>
console