给一个数组:

[{ GroupMark: "", GroupName: "hao", SendTime: '123', SendContent: "1ha" },
{ GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "2ha" },
{ GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "3ha" },
{ GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "4ha" },
{ GroupMark: "3", GroupName: "hao", SendTime: '123', SendContent: "6ha" },
{ GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "5ha" }]

目标

[{"GroupMark":"","GroupName":"hao","SendTime":"123","SendContent":["1ha"]},
{"GroupMark":"1","GroupName":"hao","SendTime":"123","SendContent":["2ha","3ha"]},
{"GroupMark":"22","GroupName":"hao","SendTime":"123","SendContent":["4ha","5ha"]},
{"GroupMark":"3","GroupName":"hao","SendTime":"123","SendContent":["6ha"]}]
//参照数组去重的
var arr =[{ GroupMark: "", GroupName: "hao", SendTime: '123', SendContent: "1ha" },
{ GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "2ha" },
{ GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "3ha" },
{ GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "4ha" },
{ GroupMark: "3", GroupName: "hao", SendTime: '123', SendContent: "6ha" },
{ GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "5ha" }]
var tempObj ={}
var resArr = []
for(let [index,item] of arr.entries() ){
let {GroupMark,GroupName,SendContent} = item
let keyStr = GroupMark+'&'+GroupName
if(tempObj[keyStr]){
let tempSendContent= tempObj[keyStr].SendContent
tempObj[keyStr].SendContent=[...tempSendContent,SendContent]
}else{
tempObj[keyStr]={
...item,
SendContent:[SendContent]
}
}
}
for (let item in tempObj) {
resArr.push(tempObj[item])
}
console.log(resArr)

最新文章

  1. Bootstrap之样式风格与下拉菜单
  2. sql查询工程结算分包款转出
  3. (PHP)程序中如何判断当前用户终端是手机等移动终端
  4. MSSQL PIVOT 实现行列转置
  5. jQuery Validate 表单验证
  6. Linux和Windows路由配置
  7. solaris bind 符号未定义
  8. GitHub初次使用记录(一)
  9. Apache Mesos_百度百科
  10. 在不同Activity之间传递数据的四种常用方法
  11. 深入浅出KnockoutJS
  12. FMDB的一些基本操作小结
  13. 通过Servlet实现汉字验证码
  14. 将你的Python Web程序部署到Ubuntu服务器上
  15. 【一天一道LeetCode】#63. Unique Paths II
  16. python进阶之time模块详解
  17. 20175317 《Java程序设计》第六周学习总结
  18. 物流一站式查询之TrackingMore篇
  19. ceph:如何处理rados --striper上传失败的对象
  20. UVALive 6913 I Want That Cake 博弈dp

热门文章

  1. *【Python】【demo实验26】【练习实例】【递归方法的使用】
  2. 【Python】【demo实验10】【练习实例】【打印斐波那契数列】
  3. Hive远程连接
  4. Spring 循环依赖的三种方式(三级缓存解决Set循环依赖问题)
  5. STL set 常见用法详解
  6. 深入理解Python中的GIL(全局解释器锁)
  7. jmeter 工具学习 未完待续
  8. java8 List对象集合去重
  9. Java 代码运行顺序
  10. CentOS 中利用docker安装MySQL