现在有两个json对象 obj和obj2 , 需求是从对象obj2里面去匹配obj对象中的resourceno属性(obj和obj2的数量都不确定),如果匹配成功就修改obj2中的resourceid属性为1obj对象var obj = [{ id: "0", resourceno: "abc",
},
{ id: "0", resourceno: "abcd",
}]obj2对象var obj2 = [{ resourceid: "0", resourceno: "abcd",
},
{ resourceid: "0", resourceno: "kk",
},{ resourceid: "0", resourceno: "jj",
}]
1 回答
喵喔喔
TA贡献1735条经验 获得超5个赞
function reg(obj1, obj2){
for(var i = 0; i < obj1.length ; i++){
for(var j = 0; j < obj2.length ; j++){
if(obj2[j].resourceno == obj1[i].resourceno){
obj2[j].resourceid = 1
}
}
}
console.log(obj2)
}
reg(obj, obj2)
添加回答
举报
0/150
提交
取消