当前位置:网站首页>找出相同属性值的对象 累加数量 汇总
找出相同属性值的对象 累加数量 汇总
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;
}

边栏推荐
- xss-labs靶场挑战
- The CAN communication standard frame and extended frame is introduced
- 【社区明星评选】第24期 8月更文计划 | 笔耕不辍,拒绝躺平!更多原创激励大礼包,还有华为WATCH FIT手表!
- RK3399 platform development series on introduction to (kernel) 1.52, printk function analysis - the function call will be closed
- OpenHarmony高校技术俱乐部计划发布
- R语言拟合ARIMA模型:使用forecast包中的auto.arima函数自动搜索最佳参数组合、模型阶数(p,d,q)、设置seasonal参数指定在模型中是否包含季节信息
- Aeraki Mesh became CNCF sandbox project
- 这是我见过写得最烂的Controller层代码,没有之一!
- C#/VB.NET 将PPT或PPTX转换为图像
- Deep understanding of Istio - advanced practice of cloud native service mesh
猜你喜欢

进制与转换、关键字

Qt get all files in a folder

CAN通信的数据帧和远程帧
![[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement](/img/fc/cd859efa69fa7b45f173de74c04858.png)
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement

《MySQL核心知识》第6章:查询语句

How to use DevExpress controls to draw flowcharts?After reading this article, you will understand!

Qt获取文件夹下所有文件

Promise学习(二)一篇文章带你快速了解Promise中的常用API

Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report

重庆市大力实施智能建造,推动建筑业数字化转型,助力“建造强市”
随机推荐
NIO‘s Sword(思维,取模,推公式)
Ts-Map 类的使用
C language implementation!20000 in 4 seconds
SCHEMA solves the puzzle
分类预测 | MATLAB实现1-DCNN一维卷积神经网络分类预测
C#/VB.NET 将PPT或PPTX转换为图像
【随心笔记】假期快过去了,都干了点什么
xss漏洞学习
ddl and dml in sql (the difference between database table and view)
C语言实现!20000用4秒计算
Several methods of appending elements are commonly used in js: append, appendTo, after, before, insertAfter, insertBefore, appendChild
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
【无标题】
Stone Technology builds hard-core brand power and continues to expand the global market
如何利用DevExpress控件绘制流程图?看完这篇文章就懂了!
通配符SSL证书不支持多域名吗?
正则表达式
判断JS数据类型的四种方法
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化密度图、使用stat_central_tendency函数在密度中添加均值竖线并自定义线条类型
activiti工作流的分页查询避坑