当前位置:网站首页>数组对象实现一 一对比(索引和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" },
],
},
];
边栏推荐
- Iplook, as a member of o-ran alliance, will jointly promote the development of 5g industry
- STM32 control matrix key, Hal library, cubemx configuration
- Digital supply chain centralized purchase platform solution for mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
- 程序员工具大全【持续更新】
- Pull down refresh and pull up to load more listviews
- Vs Code suddenly fails to jump
- jniLibs. Srcdirs = ['LIBS'] what's the use?
- ssh免密码登录
- 5g short message solution
- 实践出真知:全网最强秒杀系统架构解密,不是所有的秒杀都是秒杀!!
猜你喜欢

After reading the hated courage

Digital business cloud: build a digital supply chain system to enable enterprises to optimize and upgrade their logistics supply chain

Detailed explanation of session mechanism and related applications of session
![jniLibs. Srcdirs = ['LIBS'] what's the use?](/img/d5/3070f8e793507efc601bb22d5024fa.png)
jniLibs. Srcdirs = ['LIBS'] what's the use?

AUTOCAD——五种标注快捷键

结构型模式之代理模式

Thread pool: reading the source code of threadpoolexcutor

面试MySQL

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

Robotframework installation tutorial
随机推荐
Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)
机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效
【干货|接口测试必备技能-常见接口协议解析】
Detailed explanation of shell script (x) -- how to use sed editor
Sre is bound to move towards the era of chaotic engineering -- Huawei cloud chaotic engineering practice
Digital supply chain centralized purchase platform solution for mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
下拉刷新及上拉加载更多的ListView
泡泡玛特:空洞的灵魂需要故事
Flutter series -dart basic grammar learning
AIOps 智能运维经验分享
Flutter系列-搭建Flutter开发环境
Niuke.com: consolidation interval
输入两个字符串,输出最长相同子串
jniLibs.srcDirs = [‘libs‘]有什么用?
贪心之区间问题(3)
2022 G2 power plant boiler stoker question bank and online simulation examination
Thread pool: reading the source code of threadpoolexcutor
jniLibs. Srcdirs = ['LIBS'] what's the use?
Do you use thread or service?
2022 operation of simulated examination platform for examination question bank of welder (elementary) special operation certificate