按条件把一个json的值赋值到另一个json里面
例如:letobj1=[{disable:true,status:''},{disable:false,status:''},{disable:false,status:...
例如:
let obj1 = [
{disable: true, status: ''},
{disable: false, status: ''},
{disable: false, status: ''},
{disable: true, status: ''}
]
let obj2 = [
{status: 1},
{status: 8}
]
输出:
[
{disable: true, status: ''},
{disable: false, status: '1'},
{disable: false, status: '8'},
{disable: true, status: ''}
] 展开
let obj1 = [
{disable: true, status: ''},
{disable: false, status: ''},
{disable: false, status: ''},
{disable: true, status: ''}
]
let obj2 = [
{status: 1},
{status: 8}
]
输出:
[
{disable: true, status: ''},
{disable: false, status: '1'},
{disable: false, status: '8'},
{disable: true, status: ''}
] 展开
展开全部
let obj1 = [
{disable: true, status: ''},
{disable: false, status: ''},
{disable: false, status: ''},
{disable: true, status: ''}
];
let obj2 = [
{status: 1},
{status: 8}
];
obj2.forEach(function(e2){
obj1.some(function(e1){
if(!e1.disable&&e1.status==''){
e1.status=e2.status;
return true;
}
});
});
console.log(obj1);
{disable: true, status: ''},
{disable: false, status: ''},
{disable: false, status: ''},
{disable: true, status: ''}
];
let obj2 = [
{status: 1},
{status: 8}
];
obj2.forEach(function(e2){
obj1.some(function(e1){
if(!e1.disable&&e1.status==''){
e1.status=e2.status;
return true;
}
});
});
console.log(obj1);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询