web123456

JS number combination merges two jsons with the same key value into an array Double for loop

// for json1 // for json2 var listAllmanage = [], getIdIndex = {}; for (var i = 0; i < this.getdeptIdList.length; i++) { for (var j = 0; j < this.manageList.length; j++) { if (this.getdeptIdList[i].deptId == this.manageList[j].deptId) { var item if (getIdIndex[this.getdeptIdList[i].deptId] == undefined) { getIdIndex[this.getdeptIdList[i].deptId] = listAllmanage.length; item = {}; for (var attr in this.getdeptIdList[i]) item[attr] = this.getdeptIdList[i][attr]; listAllmanage[getIdIndex[this.getdeptIdList[i].deptId]] = item; } else item = listAllmanage[getIdIndex[this.getdeptIdList[i].deptId]]; for (var attr in this.manageList[j]) item[attr] = this.manageList[j][attr]; } } } console.log(listAllmanage)