当前位置:网站首页>Compare the new and old data to find the added and deleted ones
Compare the new and old data to find the added and deleted ones
2022-07-28 13:13:00 【Pig Xiaoyong】
Compare new data with old data , Find the added and deleted , Put them in two arrays
Compare two arrays , First find the same , Compare with the original array and the new array to remove duplicates
When the array is an object , You can select the only attribute in the object for comparison
const values = await this.form.validateFields();
const {
oldData } = this.state;// Old data
let oldDataRepetition = [].concat(oldData); // Merge with empty arrays , After that, the operation does not change the original array
const dataSource = values.companyInfo;// The new data
let dataSourceRepetition = [].concat(dataSource);
let someArr = []; // same
for (let i = 0; i < dataSource.length; i++) {
for (let j = 0; j < oldData.length; j++) {
if (oldData[j].companyId.value === dataSource[i].companyId.value) {
someArr.push(oldData[j]);
}
}
}
let deleteArr = []; // Delete the
for (let i = 0; i < someArr.length; i++) {
for (let j = 0; j < oldDataRepetition.length; j++) {
if (someArr[i].companyId.value === oldDataRepetition[j].companyId.value) {
oldDataRepetition.splice(j, 1); // duplicate removal
}
}
}
deleteArr = oldDataRepetition;
let addArr = []; // To increase the
for (let i = 0; i < someArr.length; i++) {
for (let j = 0; j < dataSourceRepetition.length; j++) {
if (someArr[i].companyId.value === dataSourceRepetition[j].companyId.value) {
dataSourceRepetition.splice(j, 1); // duplicate removal
}
}
}
addArr = dataSourceRepetition;
边栏推荐
- Science heavyweight: AI design protein has made another breakthrough, and it can design specific functional proteins
- 企业数字化本质
- 一根筋教育PHP培训 知行合一收热捧
- 机器学习基础-集成学习-13
- Machine learning Basics - decision tree-12
- How to view win11 system and reserved space?
- 【嵌入式C基础】第6篇:超详细的常用的输入输出函数讲解
- Unity—“合成大西瓜”小游戏笔记
- What if the right button of win11 start menu doesn't respond
- 黑猫带你学UFS协议第2篇:UFS相关名词释义
猜你喜欢

Shenwenbo, researcher of the Hundred Talents Program of Zhejiang University: kernel security in the container scenario

How does kotlin help you avoid memory leaks?

Redefinition problem of defining int i variable in C for loop

Aragon创建DAO polygon BSC测试网

机器学习基础-贝叶斯分析-14

How to add PDF virtual printer in win11

【嵌入式C基础】第1篇:基本数据类型

Full disclosure! Huawei cloud distributed cloud native technology and Practice

【嵌入式C基础】第6篇:超详细的常用的输入输出函数讲解

Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
随机推荐
[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things
Dimming and color matching cool light touch chip-dlt8ma12ts-jericho
如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南
Leetcode daily question (2196. create binary tree from descriptions)
[embedded C foundation] Part 6: super detailed explanation of common input and output functions
【嵌入式C基础】第2篇:进制转换与BCD编码
机器学习实战-逻辑回归-19
What is C generic, generic cache, generic constraint
What if the right button of win11 start menu doesn't respond
Interview must ask, focus! Tell me about the Android application startup process and its source code?
[embedded explanation] key scanning based on finite state machine and stm32
Problem solving during copilot trial
Chinese translation of pointnet:deep learning on point sets for 3D classification and segmentation
How can non-standard automation equipment enterprises do well in product quality management with the help of ERP system?
[graduation design] heart rate detection system based on single chip microcomputer - STM32 embedded Internet of things
[FPGA]: MATLAB generates COE files
2020-12-13
What if the win11 folder cannot be opened
[embedded C foundation] Part 5: original code / inverse code / complement code
[embedded C foundation] Part 1: basic data types