js对比两个json对象

现在有两个json对象 obj和obj2 , 需求是从对象obj2里面去匹配obj对象中的resourceno属性(obj和obj2的数量都不确定),如果匹配成功就修改obj2中的resourceid属性为1

obj对象

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",
            }]


月关宝盒
浏览 2365回答 1
1回答

喵喔喔

function reg(obj1, obj2){&nbsp; &nbsp; for(var i = 0; i < obj1.length ; i++){&nbsp; &nbsp; &nbsp; &nbsp; for(var j = 0; j < obj2.length ; j++){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(obj2[j].resourceno == obj1[i].resourceno){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj2[j].resourceid = 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; console.log(obj2)}reg(obj, obj2)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript