SOURCE

function safeGet(target, selector) {
    return selector
    .replace(/\[([^\[\]]*)\]/g, '.$1')
    .split('.')
    .reduce((obj, cur) => obj && obj[cur], target)
}

const a = {
    b: [
        {
            t1: 1,
            t2: 2,
        },
        {
            t1: 1,
            t2: 2,
        },
    ],
    c: {
        d: 1,
        e: 2,
    }
}

console.log(safeGet(a, 'b[3].t2'))
console 命令行工具 X clear

                    
>
console