SOURCE

function combine(chunks) {
    let res = []
    let helper = function (chunkIndex, prev) {
        let chunk = chunks[chunkIndex].list
        let name = chunks[chunkIndex].title
        let isLast = chunkIndex === chunks.length - 1
        console.log('chunk', chunk)
        console.log('isLast', isLast)
        for (let val of chunk) {
            console.log('val', val)
            let cur = prev.concat(val)
            console.log('cur', cur)
            // if (isLast) {
            //     // 如果已经处理到数组的最后一项了 则把拼接的结果放入返回值中
            //     res.push({
            //         specs: cur,
            //     })
            // } else {
            //     helper(chunkIndex + 1, cur)
            // }
        }
    }
    // 从属性数组下标为 0 开始处理
    // 并且此时的 prev 是个空数组
    helper(0, [])
    return res
}

const specList = [
    { title: "颜色", list: ["红色", "紫色", "白色", "黑色"] },
    { title: "套餐", list: ["套餐一", "套餐二", "套餐三", "套餐四"] },
    { title: "内存", list: ["64G", "128G", "256G"] }
]
// const specList = [
//     { title: "颜色", list: ["红色"] },
//     { title: "套餐", list: ["套餐一"] },
//     { title: "内存", list: ["64G"] }
// ]

let skuList = combine(specList)
console 命令行工具 X clear

                    
>
console