web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

2个数组,相同数据合并后不同数据合并(删除指定

683 ℃

1、删除指定索引

复制代码function Arrdel(a1, a2) {
  let arr = [];
  a2.forEach(item => {
	a1.splice(item, 1)
  })
  //过滤
  arr = a1.filter(item => item);
  return arr;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2、拿到相同数组和不同数组

复制代码let arr1 = [{examNo:1231,name:'中国',age:20},{examNo:3211,name:'美国',age:20}]
let arr2 = [{examNo:1231,sex:'男',fam:2},{examNo:'',sex:'女',fam:21}]
let appointmentListArr1 = [];
let appointmentListArr2 = [];
for (let i = 0; i < arr1.length; i++) {
	for (let j = 0; j < arr2.length; j++) {
	  if (arr1[i].examNo === arr2[j].examNo) {
		//获取相同数组
		appointmentListArr1.push(arr1[i]);
		appointmentListArr2.push(arr2[j]);
		//删除相同数组
		this.Arrdel(arr1, [i])
		this.Arrdel(arr2, [j])
	  }
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

3、相同数组合并

复制代码const appointmentListArr = appointmentListArr1.map((item, index) => {
	return { ...item, ...appointmentListArr2[index] };
});
  • 1
  • 2
  • 3

4、不同数组合并

复制代码const appointmentListArr3 =  arr1.map((item, index) => {
	return { ...item, ...arr2[index] };
});
  • 1
  • 2
  • 3

5、总合并

复制代码const appointmentListArrList = appointmentListArr.concat(appointmentListArr3)
  • 1

6、结果

复制代码console.log('结果',appointmentListArrList)
[
    {
        "examNo": 1231,
        "name": "中国",
        "age": 20,
        "sex": "男",
        "fam": 2
    },
    {
        "examNo": "",
        "name": "美国",
        "age": 20,
        "sex": "女",
        "fam": 21
    }
]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

js根据相同key合并生成子数组children(兼容ie10)

javascript根据相同id合并形成child子数组(支持低版本浏览器)

js数组里的对象相同key合并,其余多个相同key值相加

nodejs文件的分片与合并上传介绍

php合并两个数组后如何排序

标签: 合并

上面是“2个数组,相同数据合并后不同数据合并(删除指定”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_121.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > vuejs
本文共计1035个字,预计阅读时长7分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费可商用英文字体——Atkinson Hyperlegible
下一篇: 推荐一款免费好看的中文设计字体——字体传奇特战体
回到顶部
x 打工人ai神器