当前位置:网站首页>Find objects with the same property value Cumulative number Summarize
Find objects with the same property value Cumulative number Summarize
2022-08-01 12:02:00 【Snow Xiaoxin】
Find objects with the same property value 累加数量 汇总
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;
}

边栏推荐
- 小程序插件如何帮助开发者受益?
- [Community Star Selection] Issue 24 August Update Plan | Keep writing, refuse to lie down!More original incentive packages, as well as Huawei WATCH FIT watches!
- 【倒计时5天】探索音画质量提升背后的秘密,千元大礼等你来拿
- (ES6以上以及TS) Map对象转数组
- 【随心笔记】假期快过去了,都干了点什么
- 表达式引擎在转转平台的实践
- R语言ggplot2可视化:使用ggpubr包的ggscatter函数可视化散点图、使用xscale函数指定X轴坐标轴度量调整方式、设置x轴坐标为scientific使用科学计数法显示坐标值
- CAN通信标准帧和扩展帧介绍
- STM32 CAN过滤器配置详解
- Promise学习(一)Promise是什么?怎么用?回调地狱怎么解决?
猜你喜欢
随机推荐
[Nodejs] fs module of node
R语言ggplot2可视化:使用ggpubr包的ggscatter函数可视化散点图、使用xscale函数指定X轴坐标轴度量调整方式、设置x轴坐标为scientific使用科学计数法显示坐标值
Istio Meetup China:全栈服务网格 - Aeraki 助你在 Istio 服务网格中管理任何七层流量
音视频技术开发周刊 | 256
(ES6以上以及TS) Map对象转数组
Istio Meetup China: Full Stack Service Mesh - Aeraki Helps You Manage Any Layer 7 Traffic in an Istio Service Mesh
How do programmers solve online problems gracefully?
迁移学习冻结网络的方法:
R语言诊断ARIMA模型:forecast包构建了一个ARIMA模型、使用checkresiduals函数诊断ARIMA模型、并进行结果解读(拟合较差的ARIMA模型具有的特点)
OpenHarmony高校技术俱乐部计划发布
Several methods of appending elements are commonly used in js: append, appendTo, after, before, insertAfter, insertBefore, appendChild
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
解决vscode输入! 无法快捷生成骨架(新版vscode快速生成骨架的三种方法)
CloudCompare & PCL ICP registration (point to face)
Aeraki Mesh 加入 CNCF 云原生全景图
Promise learning (1) What is Promise?how to use?How to solve callback hell?
在线GC日志分析工具——GCeasy
R language ggplot2 visualization: use ggpubr package ggscatter function visualization scatterplot, use xscale wasn't entirely specified X axis measurement adjustment function, set the X coordinate for
每日一题:连续子数组的最大和(动态规划)
安装apex报错







