葬空吟 2023-04-20 17:08 采纳率: 61%
浏览 30
已结题

js中的数据处理,按条件合并字段内容

如下有val数组,如何处理,能够将modeldefect相同的内容json 合并,并且将checkpoint 字段处理成内容合并,用" | "分格,将level_score,num_score,repeat_score,cycle_score字段处理成新的数组字段,total_score字段做和

val = [
{
    production_date: '2023-04-18',
    checkpoint: 'ZP',
    model: 'one',
    defect: '坑',
    dept: 'AAA',
    level_score: '',
    num_score: '',
    repeat_score: 'ZP复发',
    cycle_score: '',
    total_score: 25
  },
{
    production_date: '2023-04-18',
    checkpoint: 'ZQ',
    model: 'two',
    defect: '包',
    dept: 'AAA',
    level_score: '',
    num_score: '',
    repeat_score: 'ZQ复发',
    cycle_score: '',
    total_score: 25
  },
{
    production_date: '2023-04-18',
    checkpoint: 'ZW',
    model: 'one',
    defect: '坑',
    dept: 'AAA',
    level_score: 'ZW等级',
    num_score: '',
    repeat_score: 'ZW复发',
    cycle_score: '',
    total_score: 45
  },
]

生成结果:


new_val = [
{
    production_date: '2023-04-18',
    checkpoint: 'ZP | ZW',
    model: 'one',
    defect: '坑',
    dept: 'AAA',
    tags:[ 'ZW等级', 'ZP复发', 'ZW复发'],
    total_score: 70
  },
{
    production_date: '2023-04-18',
    checkpoint: 'ZQ',
    model: 'two',
    defect: '包',
    dept: 'AAA',
    tags:['ZQ复发'],
    total_score: 25
  },
]
  • 写回答

4条回答 默认 最新

  • 唯气质长存 2023-04-20 17:15
    关注

    这不就遍历就完事了吗?model 和 defect 的值相同的就该求和的求和 该字符串拼接的拼接 该转数组转数组

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月20日
  • 创建了问题 4月20日

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表