当前位置:网站首页>数组对象实现一 一对比(索引和id相同的保留原数据,原数组没有的数据从默认列表加进去)
数组对象实现一 一对比(索引和id相同的保留原数据,原数组没有的数据从默认列表加进去)
2022-06-22 18:05:00 【凹凸曼与程序猿】
数组对象实现一 一对比(索引和id相同的保留原数据,原数组没有的数据从默认列表加进去)
// 接口数据(缺数据)
let arr1 = [
{
left: [
{
id: 1, name: "cc", check: true, displayName: "检测框IOU" },
{
id: 2, name: "yy", check: true, displayName: "aaa" },
{
id: 3, name: "dd", check: false, displayName: "ixxxxou" },
],
},
{
left: [
{
id: 1, name: "cc", check: false, displayName: "iou" },
{
id: 2, name: "yy", check: true, displayName: "aaa" },
{
id: 3, name: "dd", check: true, displayName: "ixxxxou" },
],
},
];
// 默认数据(全数据)
let arr2 = [
{
left: [
{
id: 1, name: "cc", check: false, displayName: "检测框IOU" },
{
id: 2, name: "yy", check: false, displayName: "aaa" },
{
id: 3, name: "dd", check: false, displayName: "ixxxxou" },
{
id: 4, name: "dd", check: false, displayName: "xin1" },
{
id: 5, name: "dd", check: false, displayName: "xin2" },
],
},
];
arr1.forEach((item1,index1)=>{
let arr3 = item1.left
arr2[0].left.forEach((item2)=>{
let isEqual = false;
arr3.forEach((item3)=>{
if(item2.id === item3.id){
isEqual = true;
return false;
}
})
if(!isEqual){
arr1[index1].left.push(item2);
}
})
})
console.log(arr1)//最终拼接好的数组
arr1: [
{
left: [
{
id: 1, name: "cc", check: true, displayName: "检测框IOU" },
{
id: 2, name: "yy", check: true, displayName: "aaa" },
{
id: 3, name: "dd", check: false, displayName: "ixxxxou" },
{
id: 4, name: "dd", check: false, displayName: "xin1" },
{
id: 5, name: "dd", check: false, displayName: "xin2" },
],
},
{
left: [
{
id: 1, name: "cc", check: false, displayName: "iou" },
{
id: 2, name: "yy", check: true, displayName: "aaa" },
{
id: 3, name: "dd", check: true, displayName: "ixxxxou" },
{
id: 4, name: "dd", check: false, displayName: "xin1" },
{
id: 5, name: "dd", check: false, displayName: "xin2" },
],
},
];
边栏推荐
猜你喜欢

session机制详解以及session的相关应用

shell脚本详解(四)——循环语句之while循环和until循环(附加例题及解析)

Niuke.com: judge whether it is palindrome string

Dynamically changing the style of label elements in a loop

STM32控制矩阵按键,HAL库,cubeMX配置

Several important viewpoints on operation and maintenance, monitoring and aiops
![[dry goods | necessary skills for interface testing common interface protocol analysis]](/img/6f/752078d6aac782c48c13c5d04ac525.png)
[dry goods | necessary skills for interface testing common interface protocol analysis]

Interview MySQL

Service实战:使用Service完成一个下载任务

IPLOOK和思博伦通信建立长期合作
随机推荐
session机制详解以及session的相关应用
上半年,这个领域竟出了7家新独角兽,资本争抢入局
Digital supply chain centralized purchase platform solution for mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
贪心之区间问题(2)
Detailed explanation of shell script (x) -- how to use sed editor
shell脚本详解(四)——循环语句之while循环和until循环(附加例题及解析)
Several important viewpoints on operation and maintenance, monitoring and aiops
输入两个字符串,输出最长相同子串
结构型模式之装饰者模式
5GC和卫星融合通信方案
Digital business cloud: build a digital supply chain system to enable enterprises to optimize and upgrade their logistics supply chain
2022 G2 power plant boiler stoker question bank and online simulation examination
Is flush easy to open an account? Is it safe to open a mobile account?
一款支持HomeKit的摄像头?智汀 IPC摄像头IC1开箱体验
Service practice: use service to complete a download task
助力客户数字化转型,构建全新的运维体系
3GPP 5g R17 standard is frozen, and redcap as an important feature deserves attention!
Flutter系列-Dart基础语法学习
实验4 NoSQL和关系数据库的操作比较
Flutter2.0运行在web上不同渲染器的问题