SOURCE

/*
把entry转换成如下结构
{
    'a.b.c.dd': 'abcdd',
    'a.d.xx': 'adxx',
    'a.e': 'ae'
}
*/
const entry = {
    a: {
        b: {
            c: {
                dd: 'abcdd'
            }
        },
        d: {
            xx: 'adxx'
        },
        e: 'ae'
    }
}

const fn1 = (entry) => {
    let res = {}
    let stack = []
    stack.push({
        prop: '',
        val: entry
    })
    while(stack.length){
        const { prop, val } = stack.pop()
        for(let key in val){
            const item = val[key]
            const path = `${prop}${prop&&'.'}${key}`
            if(typeof item === 'object'){
                stack.push({
                    prop: path,
                    val: item
                })
            } else {
                res[path] = item
            }
        }
    }
    return res
}

console.log(fn1(entry))
console 命令行工具 X clear

                    
>
console