当前位置:网站首页>找出相同属性值的对象 累加数量 汇总
找出相同属性值的对象 累加数量 汇总
2022-08-01 11:33:00 【淋雪小新】
找出相同属性值的对象 累加数量 汇总
const oldArray = [
{
batchNo: "1",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 1,
},
{
batchNo: "1",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 3,
},
{
batchNo: "1",
factoryCnName: "梨子",
goodsCnName: "lizi",
inputNum: 3,
},
{
batchNo: "1",
factoryCnName: "梨子",
goodsCnName: "lizi",
inputNum: 3,
},
{
batchNo: "2",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 3,
},
];
const sumTabData = countTabFun(oldArray);
//汇总数据
export function countTabFun(arr) {
const data = arr.reduce((total, cur, index) => {
let hasValue = total.findIndex((current) => {
return (
current.batchNo == cur.batchNo &&
current.factoryCnName == cur.factoryCnName &&
current.goodsCnName == cur.goodsCnName
);
});
hasValue == -1 && total.push(cur);
hasValue != -1 &&
(total[hasValue].inputNum = total[hasValue].inputNum + cur.inputNum);
return total;
}, []);
return data;
}
边栏推荐
- Visualization of lag correlation of two time series data in R language: use the ccf function of the forecast package to draw the cross-correlation function, and analyze the lag correlation according t
- Pytest电商项目实战(下)
- shell--第九章练习
- 【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
- jmeter
- 【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化密度图、使用stat_central_tendency函数在密度中添加均值竖线并自定义线条类型
- 程序员如何优雅地解决线上问题?
- Deep understanding of Istio - advanced practice of cloud native service mesh
- Why Metropolis–Hastings Works
猜你喜欢
Stone Technology builds hard-core brand power and continues to expand the global market
程序员如何优雅地解决线上问题?
利用正则表达式的回溯实现绕过
Promise learning (1) What is Promise?how to use?How to solve callback hell?
音视频技术开发周刊 | 256
新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
大众碰到点评的一个字体反爬,落地技术也是绝了
千万级乘客排队系统重构&压测方案——总结篇
Qt get all files in a folder
随机推荐
基于ArkUI eTS开发的坚果食谱(NutRecipes)
冰冰学习笔记:gcc、gdb等工具的使用
Online - GCeasy GC log analysis tools
A new generation of ultra-safe cellular batteries, Sihao Airun goes on sale starting at 139,900 yuan
如何利用DevExpress控件绘制流程图?看完这篇文章就懂了!
Aeraki Mesh 加入 CNCF 云原生全景图
[Nodejs] node的fs模块
Deep understanding of Istio - advanced practice of cloud native service mesh
Introduction to STM32 development Introduce IIC bus, read and write AT24C02 (EEPROM) (using analog timing)
Transfer learning to freeze the network:
Qt get all files in a folder
CAN通信的数据帧和远程帧
一篇文章,带你详细了解华为认证体系证书(1)
监视网络连接的ss命令
Promise学习(一)Promise是什么?怎么用?回调地狱怎么解决?
SCHEMA solves the puzzle
JWT
用户体验 | 如何度量用户体验 ?
Stone Technology builds hard-core brand power and continues to expand the global market
[CLion] CLion always prompts "This file does not belong to any project target xxx" solution