1、删除指定索引
function Arrdel(a1, a2) {
let arr = [];
a2.forEach(item => {
a1.splice(item, 1)
})
//过滤
arr = a1.filter(item => item);
return arr;
}
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])
}
}
}
3、相同数组合并
const appointmentListArr = appointmentListArr1.map((item, index) => {
return { ...item, ...appointmentListArr2[index] };
});
4、不同数组合并
const appointmentListArr3 = arr1.map((item, index) => {
return { ...item, ...arr2[index] };
});
5、总合并
const appointmentListArrList = appointmentListArr.concat(appointmentListArr3)
6、结果
console.log('结果',appointmentListArrList)
[
{
"examNo": 1231,
"name": "中国",
"age": 20,
"sex": "男",
"fam": 2
},
{
"examNo": "",
"name": "美国",
"age": 20,
"sex": "女",
"fam": 21
}
]
js根据相同key合并生成子数组children(兼容ie10)
javascript根据相同id合并形成child子数组(支持低版本浏览器)
上面是“2个数组,相同数据合并后不同数据合并(删除指定”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_121.html
workflows工作流
一个迷人的女人ComfyUI工作流
在月球上穿着太空服的宇航员
一匹热血沸腾的汗血宝马庄严地站立着ComfyUI工作流
3d卡通风格多彩头发的女人
一棵白色心形流苏树comfyui工作流
stvmccrr风格的玫瑰花ComfyUI工作流
一桌精致的美食,桌上几杯白葡萄酒
沙漠里一只红黑相间的蝎子
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

如何利用css3+js做一个下雨效果
jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
js+css3做一个灯泡开灯关灯效果
纯html+css做一个3d统计效果
黑客入侵效果代码
2023年程序猿如何给自己开启一场烟花盛会
css3绘制一个会动的大嘴鸟
3d文字动画效果











