二维数组数据动态组合

根据下面二维数组,

const list = [{
    port: ["a","b"],
    supplier: ["c","d"],
    carrir: ["e","f"],
    name: "222"
}]

生成如下数据格式:

['ace222,ade222,acf222,adf222,bce222,bde222,bcf222,bdf222]

具体实现方法

const setArray = (data) => {
    return data.reduce((items, index) => {
        if (!Array.isArray(items) '' !Array.isArray(index)) {
            return
        }
        if (items.length === 0) {
            return index
        }
        if (index.length === 0) {
            return items
        }
        const temp = []
        items.forEach(val => {
            index.forEach(item => {
                temp.push(<code class="kb-btn">${val}${item}</code>)
            })
        })
        return temp
    }, [])
}
const arr = []
list.map((r) => {
    Object.keys(r).map((item) => {
        arr.push(typeof r[item] === "string" ? r[item].split(",") : r[item])
    })
})
console.log(setArray(arr))