卖坚果的怪叔叔 卖坚果的怪叔叔
  • 首页
  • 技术
  • 生活
  • 记录
  • 朋友
  • 常用代码
  • 工具箱
  • 关于
  • 1

二维数组数据动态组合

坚果大叔
2022-07-28 10:50:47

根据下面二维数组,

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))


微信扫描下方的二维码阅读本文

JavaScript
1
本文系作者 @坚果大叔 原创发布在 卖坚果的怪叔叔。未经许可,禁止转载。
Vite自动全局注册组件!
上一篇
夕阳
下一篇

评论已关闭

坚果大叔

255
文章
66
评论
207
喜欢

近期文章

  • instanceof和typeof的区别
  • 嗖嗖嗖
  • 镜头下的一点记录!
  • React实现打字机效果~
  • 一晃又周三了

猜你喜欢

instanceof和typeof的区别

2023-09-26 17:20:33
56 0 0

React实现打字机效果~

2023-08-22 17:31:49
300 0 1

Mac更换node版本切换工具n模块的镜像源

2023-07-13 13:21:45
279 2 2

Md5引发的血案

2023-07-03 16:45:00
412 0 1
1

博主

一枚佛系前端开发,会一丢丢摄影,喜欢折腾,爱好美食。分享点前端技巧、笔记以及各种有趣的APP和资源教程♥♥

友链

Lieme

公众号

坚果大叔 执行上下文 卖坚果的怪叔叔
Copyright © 2017-2023 卖坚果的怪叔叔. Designed by nicetheme.

萌ICP备20230818号 苏ICP备18048410号-2
  • 首页
  • 技术
  • 生活
  • 记录
  • 朋友
  • 常用代码
  • 工具箱
  • 关于

搜索

  • 微信机器人
  • CSS
  • js
  • git

坚果大叔

255
文章
66
评论
207
喜欢